Gosaxml is a streaming XML decoder and encoder, similar in interface to the encoding/xml

gosaxml is a streaming XML decoder and encoder, similar in interface to the encoding/xml, but with a focus on performance, low memory footprint and on fixing many of the issues present in encoding/xml mainly related to handling of namespaces (see https://github.com/golang/go/issues/13400).

In addition to handling namespaces, gosaxml can also canonicalize and minify XML namespaces bindings in a document (with and without prefixes) and does not repeat the prefix-less namespace declaration on all encoded XML elements, like encoding/xml does.

Get it

go get -u github.com/HBTGmbH/gosaxml

Features

  • zero-allocation stream decoding of XML inputs (from io.Reader)
  • zero-allocation stream encoding of XML elements (to io.Writer)
  • tidying of XML namespace declarations of the encoder input

Simple examples

Decode and re-encode

The following example (in the form of a Go test) decodes from a given io.Reader and encodes the same tokens into a provided io.Writer:

Hi! `) var w bytes.Buffer dec := gosaxml.NewDecoder(r) enc := gosaxml.NewEncoder(&w) // when for { tk, err := dec.NextToken() if err == io.EOF { break } assert.Nil(t, err) err = enc.EncodeToken(tk) assert.Nil(t, err) } // then assert.Equal(t, ` Hi! ` w.String()) }">
func TestDecodeAndEncode(t *testing.T) {
	// given
	var r io.Reader = strings.NewReader(
		`
		Hi!
		
    
		`)
	var w bytes.Buffer
	dec := gosaxml.NewDecoder(r)
	enc := gosaxml.NewEncoder(&w)

	// when
	for {
		tk, err := dec.NextToken()
		if err == io.EOF {
			break
		}
		assert.Nil(t, err)

		err = enc.EncodeToken(tk)
		assert.Nil(t, err)
	}

	// then
	assert.Equal(t,
		`
		Hi!
		
    
		`
		w.String())
}
Owner
HBT Hamburger Berater Team GmbH
IT Driven Business
HBT Hamburger Berater Team GmbH
Similar Resources

WebP decoder and encoder for Go (Zero Dependencies).

WebP decoder and encoder for Go (Zero Dependencies).

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa webp ██╗ ██╗███████╗██████╗ ██████╗ ██║

Dec 28, 2022

Pure Go Brotli encoder and decoder

This package is a brotli compressor and decompressor implemented in Go. It was translated from the reference implementation (https://github.com/google

Dec 28, 2022

asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID.

asciigrid asciigrid is a Go package that implements decoder and encoder for the Esri ASCII grid format, also known as ARC/INFO ASCII GRID. Install go

Jul 3, 2022

Go encoder and decoder for the NetBPM/PNM image formats. Compatible with Go's image packages.

gpnm This package implements an encoder and decoder for PNM image formats. It can be used with Go's image library. It covers all formats as defined by

Nov 26, 2021

BMP image decoder and encoder

bmp Package bmp implements a BMP image decoder and encoder. The BMP specification is at http://www.digicamsoft.com/bmp/bmp.html. Supported BMP feature

Nov 25, 2022

Pbm - Package ppm implements a Portable Bit Map (PBM) image decoder and encoder written in Go

Package pbm import "github.com/slashformotion/pbm" Package pbm implements a Portable Bit Map (PBM) image decoder and encoder. The supported image col

Jan 5, 2022

Rich TIFF/BigTIFF/GeoTIFF decoder/encoder for Go (Pure Go/Zero Dependencies)

Go语言QQ群: 102319854, 1055927514 凹语言(凹读音“Wa”)(The Wa Programming Language): https://github.com/wa-lang/wa TIFF for Go Features: Support BigTiff Support

Nov 16, 2022

Fixed width file parser (encoder/decoder) in GO (golang)

Fixed width file parser (encoder/decoder) for GO (golang) This library is using to parse fixed-width table data like: Name Address

Sep 27, 2022

PHP session encoder/decoder written in Go

php_session_decoder PHP session encoder/decoder written in Go Installation Install: The recommended way to install is using gonuts.io: nut get yvasiya

Sep 27, 2022

Pure Go encoder/decoder of the QOI image format

QOI - The “Quite OK Image” format for fast, lossless image compression package and small utilities in native Go, quite OK implementation See qoi.h for

Nov 12, 2022

goi - The “Quite OK Image” format encoder / decoder for Go.

goi - The “Quite OK Image” format encoder / decoder for Go.

goi - The “Quite OK Image” format encoder / decoder for Go. QOI - The “Quite OK Image” - is losslessly image format that offering speedup both compres

Mar 3, 2022

ROT13 Encoder/Decoder

ROT-13 Decoder/Encoder Initially written for fun for a CTF Can take a string and encode/decode using ROT13 From Wikipedia: Applying ROT13 to a piece o

Dec 29, 2021

Decoder/Encoder for GhostControls Gate Remotes

ghostcontrols Decoder/Encoder for GhostControls Gate Remotes GhostControls makes a variety of automatic gate operators, transmitters and keypads & rec

Sep 5, 2022

Go structure annotations that supports encoding and decoding; similar to C-style bitfields. Supports bitfield packing, self-describing layout parameters, and alignment.

Go structure annotations that supports encoding and decoding; similar to C-style bitfields. Supports bitfield packing, self-describing layout parameters, and alignment.

STRUCTure EXtensions structex provides annotation rules that extend Go structures for implementation of encoding and decoding of byte backed data fram

Oct 13, 2022

Nfc-sun-decoder - A Decoder for NXP 424 DNA SUN (Secure Unique) messages

NFC SUN Decoder A Decoder for NXP 424 DNA SUN (Secure Unique) messages This library makes decoding 424 DNA SUN messages easier. While the 424 DNA chip

Aug 24, 2022

go-eexcel implements encoding and decoding of XLSX like encoding/json

go-eexcel go-eexcel implements encoding and decoding of XLSX like encoding/json Usage func ExampleMarshal() { type st struct { Name string `eexce

Dec 9, 2021

Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Nov 24, 2021
XML to MAP converter written Golang

xml2map XML to MAP converter written Golang Sometimes there is a need for the representation of previously unknown structures. Such a universal repres

Dec 8, 2022
xmlwriter is a pure-Go library providing procedural XML generation based on libxml2's xmlwriter module

xmlwriter xmlwriter is a pure-Go library providing a procedural XML generation API based on libxml2's xmlwriter module. The package is extensively doc

Sep 27, 2022
XPath package for Golang, supports HTML, XML, JSON document query.

XPath XPath is Go package provides selecting nodes from XML, HTML or other documents using XPath expression. Implementation htmlquery - an XPath query

Dec 28, 2022
Extract data or evaluate value from HTML/XML documents using XPath

xquery NOTE: This package is deprecated. Recommends use htmlquery and xmlquery package, get latest version to fixed some issues. Overview Golang packa

Nov 9, 2022
Generate a Go struct from XML.
Generate a Go struct from XML.

zek Zek is a prototype for creating a Go struct from an XML document. The resulting struct works best for reading XML (see also #14), to create XML, y

Dec 30, 2022
COBS implementation in Go (Decoder) and C (Encoder & Decoder) with tests.

COBS Table of Contents About The project COBS Specification Getting Started 3.1. Prerequisites 3.2. Installation 3.3. Roadmap Contributing License Con

May 22, 2022
Package polyline implements a Google Maps Encoding Polyline encoder and decoder.

go-polyline Package polyline implements a Google Maps Encoding Polyline encoder and decoder. Encoding example func ExampleEncodeCoords() { coords :=

Dec 1, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Jan 6, 2023
Go encoding/xml package that improves support for XML namespaces

encoding/xml with namespaces This is a fork of the Go encoding/xml package that improves support for XML namespaces, kept in sync with golang/go#48641

Nov 11, 2022
Fast, secure and efficient secure cookie encoder/decoder

Encode and Decode secure cookies This package provides functions to encode and decode secure cookie values. A secure cookie has its value ciphered and

Dec 9, 2022