Help us shape the future of Go! Take the 2026 Go Developer Survey

xml

package
v2.24.24 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2026 License: MIT Imports: 4 Imported by: 117

Documentation

Overview

Package xml minifies XML1.0 following the specifications at http://www.w3.org/TR/xml/.

Index

Examples

Constants

This section is empty.

Variables

View Source
var AttrRevEntitiesMap = map[byte][]byte{
	'\t': []byte("	"),
	'\n': []byte("
"),
	'\r': []byte("
"),
}

AttrRevEntitiesMap keeps whitespace character references; decoding them to literal tab/LF/CR would let attribute-value normalization collapse them to a space.

View Source
var EntitiesMap = map[string][]byte{
	"apos": []byte("'"),
	"quot": []byte("\""),
}

EntitiesMap are all named character entities.

View Source
var TextRevEntitiesMap = map[byte][]byte{
	'<':  []byte("&lt;"),
	'>':  []byte("&gt;"),
	'&':  []byte("&amp;"),
	'\t': []byte("&#9;"),
	'\n': []byte("&#10;"),
	'\r': []byte("&#13;"),
}

TextRevEntitiesMap is a map of escapes. It keeps whitespace character references; decoding them to literal tab/LF/CR would let text whitespace normalization collapse them to a space.

Functions

func Minify

func Minify(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error

Minify minifies XML data, it reads from r and writes to w.

Example
m := minify.New()
m.AddFuncRegexp(regexp.MustCompile("[/+]xml$"), Minify)

if err := m.Minify("text/xml", os.Stdout, os.Stdin); err != nil {
	panic(err)
}

Types

type Minifier

type Minifier struct {
	KeepWhitespace bool
}

Minifier is an XML minifier.

func (*Minifier) Minify

func (o *Minifier) Minify(m *minify.M, w io.Writer, r io.Reader, _ map[string]string) error

Minify minifies XML data, it reads from r and writes to w.

type Token

type Token struct {
	xml.TokenType
	Data    []byte
	Text    []byte
	AttrVal []byte
}

Token is a single token unit with an attribute value (if given) and hash of the data.

type TokenBuffer

type TokenBuffer struct {
	// contains filtered or unexported fields
}

TokenBuffer is a buffer that allows for token look-ahead.

func NewTokenBuffer

func NewTokenBuffer(l *xml.Lexer) *TokenBuffer

NewTokenBuffer returns a new TokenBuffer.

func (*TokenBuffer) Peek

func (z *TokenBuffer) Peek(pos int) *Token

Peek returns the ith element and possibly does an allocation. Peeking past an error will panic.

func (*TokenBuffer) Shift

func (z *TokenBuffer) Shift() *Token

Shift returns the first element and advances position.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL