Documentation
¶
Overview ¶
Package xmlstream provides a namespace-aware streaming XML reader built on xmltext. It exposes zero-copy event slices with explicit lifetimes and helper APIs for subtree copying and streaming unmarshaling.
Index ¶
- Constants
- Variables
- func JoinOptions(opts ...Option) xmltext.Options
- type Attr
- type ElementID
- type Event
- type EventKind
- type NameID
- type NamespaceDecl
- type Option
- type QName
- type RawAttr
- type RawEvent
- type RawName
- type Reader
- func (r *Reader) CurrentNamespaceDeclsSeq() iter.Seq[NamespaceDecl]
- func (r *Reader) CurrentPos() (line, column int)
- func (r *Reader) Decode(v Unmarshaler) error
- func (r *Reader) DecodeElement(v Unmarshaler, start Event) error
- func (r *Reader) InputOffset() int64
- func (r *Reader) LookupNamespace(prefix string) (string, bool)
- func (r *Reader) LookupNamespaceAt(prefix string, depth int) (string, bool)
- func (r *Reader) LookupNamespaceBytes(prefix []byte) (string, bool)
- func (r *Reader) LookupNamespaceBytesAt(prefix []byte, depth int) (string, bool)
- func (r *Reader) NamespaceDecls(depth int) []NamespaceDecl
- func (r *Reader) NamespaceDeclsSeq(depth int) iter.Seq[NamespaceDecl]
- func (r *Reader) Next() (Event, error)
- func (r *Reader) NextRaw() (RawEvent, error)
- func (r *Reader) NextResolved() (ResolvedEvent, error)
- func (r *Reader) ReadSubtreeTo(w io.Writer) (int64, error)
- func (r *Reader) Reset(src io.Reader, opts ...Option) error
- func (r *Reader) SkipSubtree() error
- type ResolvedAttr
- type ResolvedEvent
- type Unmarshaler
Constants ¶
const ( XMLNamespace = xmlnames.XMLNamespace XMLNSNamespace = xmlnames.XMLNSNamespace XSINamespace = xmlnames.XSINamespace XSDNamespace = "http://www.w3.org/2001/XMLSchema" )
Common XML namespaces.
Variables ¶
var ErrUnboundPrefix = errUnboundPrefix
ErrUnboundPrefix reports usage of an undeclared namespace prefix.
Functions ¶
func JoinOptions ¶ added in v0.0.23
JoinOptions merges xmlstream options into a single xmltext options struct.
Types ¶
type Event ¶
type Event struct {
Name QName
Attrs []Attr
Text []byte
Kind EventKind
Line int
Column int
ID ElementID
ScopeDepth int
}
Event represents a single streaming XML token. Text and Attr.Value are valid until the next Next call.
type NameID ¶ added in v0.0.16
type NameID uint32
NameID is a monotonic identifier assigned per document for expanded names.
type NamespaceDecl ¶
NamespaceDecl reports a namespace declaration on the current element.
type RawAttr ¶
RawAttr holds a raw attribute name and value. The byte slices are valid until the next Next or NextRaw call.
type RawEvent ¶
type RawEvent struct {
Name RawName
Attrs []RawAttr
Text []byte
Kind EventKind
Line int
Column int
ID ElementID
ScopeDepth int
}
RawEvent represents a streaming XML token with raw names. The byte slices are valid until the next Next or NextRaw call.
type RawName ¶
RawName holds a raw QName split into prefix and local parts. The byte slices are valid until the next Next or NextRaw call.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides a streaming XML event interface with namespace tracking.
func (*Reader) CurrentNamespaceDeclsSeq ¶ added in v0.0.23
func (r *Reader) CurrentNamespaceDeclsSeq() iter.Seq[NamespaceDecl]
CurrentNamespaceDeclsSeq yields namespace declarations in the current scope.
func (*Reader) CurrentPos ¶
CurrentPos returns the line and column of the most recent token.
func (*Reader) Decode ¶
func (r *Reader) Decode(v Unmarshaler) error
Decode unmarshals the current element subtree into v.
func (*Reader) DecodeElement ¶
func (r *Reader) DecodeElement(v Unmarshaler, start Event) error
DecodeElement unmarshals using the provided start event.
func (*Reader) InputOffset ¶
InputOffset returns the current byte position in the input stream.
func (*Reader) LookupNamespace ¶
LookupNamespace resolves a prefix in the current scope.
func (*Reader) LookupNamespaceAt ¶
LookupNamespaceAt resolves a prefix at the given scope depth.
func (*Reader) LookupNamespaceBytes ¶
LookupNamespaceBytes resolves a prefix in the current scope without allocation.
func (*Reader) LookupNamespaceBytesAt ¶
LookupNamespaceBytesAt resolves a prefix at the given scope depth without allocation.
func (*Reader) NamespaceDecls ¶
func (r *Reader) NamespaceDecls(depth int) []NamespaceDecl
NamespaceDecls returns namespace declarations at the given scope depth. The returned slice aliases reader-owned storage and is valid until the next read.
func (*Reader) NamespaceDeclsSeq ¶ added in v0.0.23
func (r *Reader) NamespaceDeclsSeq(depth int) iter.Seq[NamespaceDecl]
NamespaceDeclsSeq yields namespace declarations at the given scope depth.
func (*Reader) NextRaw ¶
NextRaw returns the next XML event with raw names. Raw name and value slices are valid until the next Next or NextRaw call.
func (*Reader) NextResolved ¶ added in v0.0.16
func (r *Reader) NextResolved() (ResolvedEvent, error)
NextResolved returns the next XML event with namespace-resolved byte slices.
func (*Reader) ReadSubtreeTo ¶ added in v0.0.23
ReadSubtreeTo streams the current element subtree to w.
func (*Reader) SkipSubtree ¶
SkipSubtree skips the current element subtree after a StartElement event.
type ResolvedAttr ¶ added in v0.0.16
ResolvedAttr holds a namespace-resolved attribute.
type ResolvedEvent ¶ added in v0.0.16
type ResolvedEvent struct {
NS []byte
Local []byte
Attrs []ResolvedAttr
Text []byte
Kind EventKind
Line int
Column int
ID ElementID
ScopeDepth int
NameID NameID
}
ResolvedEvent represents a streaming XML token with namespace-resolved bytes. NS/Local/Attr slices are valid until the next NextResolved or Next call.
type Unmarshaler ¶
Unmarshaler is implemented by types that can unmarshal themselves from XML.