xmlwire

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 13 Imported by: 3

Documentation

Overview

Package xmlwire provides bounded XML encoding and decoding with explicit namespace, root-element, strictness, and character-set policy.

Index

Constants

View Source
const (
	// DefaultMaxBytes is the default maximum XML document size.
	DefaultMaxBytes int64 = 1 << 20
	// DefaultMaxDepth is the default maximum nested XML element depth.
	DefaultMaxDepth = 1000
)

Variables

View Source
var ErrNestingTooDeep = errors.New("XML nesting exceeds depth limit")

ErrNestingTooDeep identifies XML documents over the configured depth limit.

View Source
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")

ErrPayloadTooLarge identifies XML documents over the configured limit.

Functions

func CharsetReader

func CharsetReader(label string, input io.Reader) (io.Reader, error)

CharsetReader converts a deliberately limited set of common vendor encodings to UTF-8. Unknown labels and undefined code points return errors.

func Decode

func Decode(payload []byte, target any, options DecodeOptions) error

Decode parses one complete XML document into target.

func DecodeReader

func DecodeReader(reader io.Reader, target any, options DecodeOptions) error

DecodeReader reads a bounded stream and parses one complete XML document.

func Encode

func Encode(value any, options EncodeOptions) ([]byte, error)

Encode serializes value using encoding/xml's deterministic struct traversal.

func EncodeWriter

func EncodeWriter(writer io.Writer, value any, options EncodeOptions) error

EncodeWriter serializes value and writes the complete XML document to writer.

func Root

func Root(payload []byte, options DecodeOptions) (xml.Name, error)

Root validates an XML document and returns its namespace-resolved root name.

Types

type DecodeOptions

type DecodeOptions struct {
	MaxBytes       int64
	MaxDepth       int
	AllowNonStrict bool
	ExpectedRoot   xml.Name
	CharsetReader  func(string, io.Reader) (io.Reader, error)
}

DecodeOptions controls XML parsing and validation.

type EncodeOptions

type EncodeOptions struct {
	MaxBytes      int64
	Indent        string
	IncludeHeader bool
}

EncodeOptions controls XML serialization.

Jump to

Keyboard shortcuts

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