xmlwire

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: MIT Imports: 13 Imported by: 7 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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