Documentation
¶
Overview ¶
Package helium is a fast, pure-Go XML toolkit covering XML parsing, SAX2-style streaming, XPath 3.1, XSLT 3.0, XInclude, XSD, Relax NG, and Schematron. This root package provides tree-based XML parsing, a DOM interface, SAX2 callbacks, namespace handling, DTD validation, and serialization. See the sub-packages listed below for additional features.
Parsing ¶
Use NewParser to create a parser, configure it with fluent builder methods, and call a terminal method to parse XML:
doc, err := helium.NewParser().
SubstituteEntities(true).
Parse(ctx, xmlBytes)
For file-based input, use Parser.ParseFile:
doc, err := helium.NewParser().ParseFile(ctx, "input.xml")
For streaming input, use Parser.ParseReader or Parser.NewPushParser.
Serialization ¶
Use NewWriter to serialize documents or nodes back to XML:
err := helium.NewWriter().Format(true).WriteTo(os.Stdout, doc)
DOM ¶
The document tree consists of Node values. Concrete types include Document, Element, Text, Comment, CDATASection, ProcessingInstruction, Attribute, DTD, and Namespace. Tree traversal helpers include Walk, Children, Descendants, and ChildElements.
Related packages ¶
Sub-packages provide additional XML processing:
- github.com/lestrrat-go/helium/xpath1 — XPath 1.0
- github.com/lestrrat-go/helium/xpath3 — XPath 3.1
- github.com/lestrrat-go/helium/xslt3 — XSLT 3.0
- github.com/lestrrat-go/helium/xsd — XML Schema validation
- github.com/lestrrat-go/helium/relaxng — RELAX NG validation
- github.com/lestrrat-go/helium/schematron — Schematron validation
- github.com/lestrrat-go/helium/c14n — XML Canonicalization
- github.com/lestrrat-go/helium/xinclude — XInclude processing
- github.com/lestrrat-go/helium/catalog — OASIS XML Catalog
- github.com/lestrrat-go/helium/stream — Streaming XML writer
- github.com/lestrrat-go/helium/sax — SAX2 handler interfaces
- github.com/lestrrat-go/helium/shim — Drop-in encoding/xml replacement
- github.com/lestrrat-go/helium/html — HTML parser
Examples ¶
Example code for this package lives in the examples/ directory at the repository root (files prefixed with helium_). Because examples are in a separate test module they do not appear in the generated documentation.
Index ¶
- Constants
- Variables
- func AppendChildFast(parent MutableNode, child Node) error
- func AsNode[T Node](n Node) (T, bool)
- func BuildURI(systemID, base string) string
- func ChildElements(n Node) iter.Seq[*Element]
- func Children(n Node) iter.Seq[Node]
- func ClarkName(uri, local string) string
- func CopyDTDInfo(src, dst *Document)
- func CopyExtSubset(src, dst *Document)
- func Descendants(n Node) iter.Seq[Node]
- func NewLeveledError(msg string, level ErrorLevel) error
- func NodeGetBase(doc *Document, n Node) string
- func SetNodeBaseURI(n Node, uri string)
- func StopParser(ctx context.Context)
- func UnlinkNode(n MutableNode)
- func Walk(n Node, w NodeWalker) error
- func Write(out io.Writer, node Node) error
- func WriteString(node Node) (string, error)
- type AttrNotFoundError
- type Attribute
- func (n *Attribute) AType() enum.AttributeType
- func (n *Attribute) AddChild(cur Node) error
- func (n *Attribute) AddSibling(cur Node) error
- func (n *Attribute) AppendText(b []byte) error
- func (n Attribute) Content() []byte
- func (n Attribute) FirstChild() Node
- func (n *Attribute) IsDefault() bool
- func (n Attribute) LastChild() Node
- func (n Attribute) Line() int
- func (n Attribute) LocalName() string
- func (n Attribute) Name() string
- func (n *Attribute) NextAttribute() *Attribute
- func (n Attribute) NextSibling() Node
- func (n Attribute) OwnerDocument() *Document
- func (n Attribute) Parent() Node
- func (n Attribute) Prefix() string
- func (n Attribute) PrevSibling() Node
- func (n *Attribute) Replace(nodes ...Node) error
- func (n *Attribute) SetAType(v enum.AttributeType)
- func (n *Attribute) SetDefault(b bool)
- func (n *Attribute) SetLine(line int)
- func (n *Attribute) SetNextSibling(cur Node)
- func (n *Attribute) SetOwnerDocument(doc *Document)
- func (n *Attribute) SetParent(cur Node)
- func (n *Attribute) SetPrevSibling(cur Node)
- func (n *Attribute) SetTreeDoc(doc *Document)
- func (n Attribute) Type() ElementType
- func (n Attribute) URI() string
- func (n Attribute) Value() string
- type AttributeDecl
- func (n *AttributeDecl) AType() enum.AttributeType
- func (n *AttributeDecl) AddChild(cur Node) error
- func (n *AttributeDecl) AddSibling(cur Node) error
- func (n *AttributeDecl) AppendText(b []byte) error
- func (n AttributeDecl) Content() []byte
- func (n *AttributeDecl) Elem() string
- func (n AttributeDecl) FirstChild() Node
- func (n AttributeDecl) LastChild() Node
- func (n AttributeDecl) Line() int
- func (n AttributeDecl) LocalName() string
- func (n AttributeDecl) Name() string
- func (n AttributeDecl) NextSibling() Node
- func (n AttributeDecl) OwnerDocument() *Document
- func (n AttributeDecl) Parent() Node
- func (n AttributeDecl) PrevSibling() Node
- func (n *AttributeDecl) Replace(nodes ...Node) error
- func (n *AttributeDecl) SetLine(line int)
- func (n *AttributeDecl) SetNextSibling(cur Node)
- func (n *AttributeDecl) SetOwnerDocument(doc *Document)
- func (n *AttributeDecl) SetParent(cur Node)
- func (n *AttributeDecl) SetPrevSibling(cur Node)
- func (n *AttributeDecl) SetTreeDoc(doc *Document)
- func (n AttributeDecl) Type() ElementType
- type AttributePredicate
- type CDATASection
- func (n *CDATASection) AddChild(cur Node) error
- func (n *CDATASection) AddNamespaceDecl(ns *Namespace)
- func (n *CDATASection) AddSibling(cur Node) error
- func (n *CDATASection) AppendText(b []byte) error
- func (n CDATASection) Content() []byte
- func (n *CDATASection) DeclareNamespace(prefix, uri string) error
- func (n *CDATASection) Name() string
- func (n CDATASection) Namespace() *Namespace
- func (n CDATASection) Namespaces() []*Namespace
- func (n CDATASection) Prefix() string
- func (n *CDATASection) RemoveNamespaceByPrefix(prefix string) bool
- func (n *CDATASection) Replace(nodes ...Node) error
- func (n *CDATASection) SetActiveNamespace(prefix, uri string) error
- func (n *CDATASection) SetNs(ns *Namespace)
- func (n *CDATASection) SetTreeDoc(doc *Document)
- func (n CDATASection) URI() string
- type CatalogResolver
- type Comment
- func (n *Comment) AddChild(cur Node) error
- func (n *Comment) AddNamespaceDecl(ns *Namespace)
- func (n *Comment) AddSibling(cur Node) error
- func (n *Comment) AppendText(b []byte) error
- func (n Comment) Content() []byte
- func (n *Comment) DeclareNamespace(prefix, uri string) error
- func (n *Comment) Name() string
- func (n Comment) Namespace() *Namespace
- func (n Comment) Namespaces() []*Namespace
- func (n Comment) Prefix() string
- func (n *Comment) RemoveNamespaceByPrefix(prefix string) bool
- func (n *Comment) Replace(nodes ...Node) error
- func (n *Comment) SetActiveNamespace(prefix, uri string) error
- func (n *Comment) SetNs(ns *Namespace)
- func (n *Comment) SetTreeDoc(doc *Document)
- func (n Comment) URI() string
- type DTD
- func (dtd *DTD) AddChild(cur Node) error
- func (dtd *DTD) AddElementDecl(name string, typ enum.ElementType, content *ElementContent) (*ElementDecl, error)
- func (dtd *DTD) AddEntity(name string, typ enum.EntityType, publicID, systemID, content string) (*Entity, error)
- func (dtd *DTD) AddNotation(name, publicID, systemID string) (*Notation, error)
- func (dtd *DTD) AddSibling(cur Node) error
- func (dtd *DTD) AppendText(b []byte) error
- func (dtd *DTD) AttributesForElement(elem string) []*AttributeDecl
- func (n DTD) Content() []byte
- func (dtd *DTD) ExternalID() string
- func (n DTD) FirstChild() Node
- func (dtd *DTD) ForEachEntity(fn func(name string, ent *Entity))
- func (dtd *DTD) Free()
- func (dtd *DTD) GetElementDesc(name string) (*ElementDecl, bool)
- func (n DTD) LastChild() Node
- func (n DTD) Line() int
- func (n DTD) LocalName() string
- func (dtd *DTD) LookupAttribute(name, prefix, elem string) (*AttributeDecl, bool)
- func (dtd *DTD) LookupElement(name, prefix string) (*ElementDecl, bool)
- func (dtd *DTD) LookupEntity(name string) (*Entity, bool)
- func (dtd *DTD) LookupNotation(name string) (*Notation, bool)
- func (dtd *DTD) LookupParameterEntity(name string) (*Entity, bool)
- func (n DTD) Name() string
- func (n DTD) NextSibling() Node
- func (n DTD) OwnerDocument() *Document
- func (n DTD) Parent() Node
- func (n DTD) PrevSibling() Node
- func (dtd *DTD) RegisterAttribute(attr *AttributeDecl) error
- func (dtd *DTD) RemoveElement(name, prefix string)
- func (dtd *DTD) Replace(nodes ...Node) error
- func (n *DTD) SetLine(line int)
- func (n *DTD) SetNextSibling(cur Node)
- func (n *DTD) SetOwnerDocument(doc *Document)
- func (n *DTD) SetParent(cur Node)
- func (n *DTD) SetPrevSibling(cur Node)
- func (dtd *DTD) SetTreeDoc(doc *Document)
- func (dtd *DTD) SystemID() string
- func (n DTD) Type() ElementType
- type DTDDupTokenError
- type DocProperties
- type Document
- func (d *Document) AddChild(cur Node) error
- func (d *Document) AddEntity(name string, typ enum.EntityType, externalID, systemID, content string) (*Entity, error)
- func (d *Document) AddSibling(_ Node) error
- func (d *Document) AppendText(b []byte) error
- func (n Document) Content() []byte
- func (d *Document) CreateAttribute(name, value string, ns *Namespace) (attr *Attribute, err error)
- func (d *Document) CreateCDATASection(value []byte) *CDATASection
- func (d *Document) CreateCharRef(name string) (*EntityRef, error)
- func (d *Document) CreateComment(value []byte) *Comment
- func (d *Document) CreateDTD() (*DTD, error)
- func (d *Document) CreateElement(name string) *Element
- func (d *Document) CreateElementContent(name string, etype ElementContentType) (*ElementContent, error)
- func (d *Document) CreateInternalSubset(name, externalID, systemID string) (*DTD, error)
- func (d *Document) CreateNamespace(prefix, uri string) (*Namespace, error)
- func (d *Document) CreatePI(target, data string) *ProcessingInstruction
- func (d *Document) CreateReference(name string) (*EntityRef, error)
- func (d *Document) CreateText(value []byte) *Text
- func (d *Document) DocumentElement() *Element
- func (d *Document) Encoding() string
- func (d *Document) ExtSubset() *DTD
- func (n Document) FirstChild() Node
- func (d *Document) Free()
- func (d *Document) GetElementByID(id string) *Element
- func (d *Document) GetEntity(name string) (ent *Entity, found bool)
- func (d *Document) GetParameterEntity(name string) (*Entity, bool)
- func (d *Document) HasProperty(p DocProperties) bool
- func (d *Document) IDTable() map[string]*Element
- func (d *Document) IntSubset() *DTD
- func (d *Document) InternalSubset() (*DTD, error)
- func (d *Document) IsMixedElement(name string) (bool, error)
- func (n Document) LastChild() Node
- func (n Document) Line() int
- func (n Document) LocalName() string
- func (n Document) Name() string
- func (n Document) NextSibling() Node
- func (n Document) OwnerDocument() *Document
- func (n Document) Parent() Node
- func (n Document) PrevSibling() Node
- func (d *Document) Properties() DocProperties
- func (d *Document) RawEncoding() string
- func (d *Document) RegisterID(id string, elem *Element)
- func (d *Document) Replace(_ ...Node) error
- func (d *Document) SetDocumentElement(root MutableNode) error
- func (d *Document) SetEncoding(enc string)
- func (n *Document) SetLine(line int)
- func (n *Document) SetNextSibling(cur Node)
- func (n *Document) SetOwnerDocument(doc *Document)
- func (n *Document) SetParent(cur Node)
- func (n *Document) SetPrevSibling(cur Node)
- func (d *Document) SetProperties(p DocProperties)
- func (d *Document) SetSkipIDs(v bool)
- func (d *Document) SetTreeDoc(doc *Document)
- func (d *Document) SetURL(url string)
- func (d *Document) SkipIDs() bool
- func (d *Document) Standalone() DocumentStandaloneType
- func (n Document) Type() ElementType
- func (d *Document) URL() string
- func (d *Document) Version() string
- type DocumentStandaloneType
- type Element
- func (n *Element) AddChild(cur Node) error
- func (n *Element) AddNamespaceDecl(ns *Namespace)
- func (n *Element) AddSibling(cur Node) error
- func (n *Element) AppendText(b []byte) error
- func (n Element) Attributes() []*Attribute
- func (n *Element) DeclareNamespace(prefix, uri string) error
- func (n *Element) FindAttribute(ap AttributePredicate) (*Attribute, bool)
- func (n Element) ForEachAttribute(fn func(*Attribute) bool)
- func (n *Element) GetAttribute(name string) (string, bool)
- func (n *Element) GetAttributeNS(localName, nsURI string) (string, bool)
- func (n *Element) GetAttributeNodeNS(localName, nsURI string) *Attribute
- func (n *Element) HasAttribute(name string) bool
- func (n *Element) Name() string
- func (n Element) Namespace() *Namespace
- func (n Element) Namespaces() []*Namespace
- func (n Element) Prefix() string
- func (n *Element) RemoveAttribute(name string) bool
- func (n *Element) RemoveAttributeNS(localName, nsURI string) bool
- func (n *Element) RemoveNamespaceByPrefix(prefix string) bool
- func (n *Element) Replace(nodes ...Node) error
- func (n *Element) SetActiveNamespace(prefix, uri string) error
- func (n *Element) SetAttribute(name, value string) (*Element, error)
- func (n *Element) SetAttributeNS(localname, value string, ns *Namespace) (*Element, error)
- func (n *Element) SetBooleanAttribute(name string) error
- func (n *Element) SetLiteralAttribute(name, value string) error
- func (n *Element) SetLiteralAttributeNS(localname, value string, ns *Namespace) error
- func (n *Element) SetNs(ns *Namespace)
- func (n *Element) SetTreeDoc(doc *Document)
- func (n Element) URI() string
- type ElementContent
- type ElementContentOccur
- type ElementContentType
- type ElementDecl
- func (n *ElementDecl) AddChild(cur Node) error
- func (n *ElementDecl) AddSibling(cur Node) error
- func (n *ElementDecl) AppendText(b []byte) error
- func (n ElementDecl) Content() []byte
- func (e *ElementDecl) DeclType() enum.ElementType
- func (n ElementDecl) FirstChild() Node
- func (n ElementDecl) LastChild() Node
- func (n ElementDecl) Line() int
- func (n ElementDecl) LocalName() string
- func (n ElementDecl) Name() string
- func (n ElementDecl) NextSibling() Node
- func (n ElementDecl) OwnerDocument() *Document
- func (n ElementDecl) Parent() Node
- func (n ElementDecl) PrevSibling() Node
- func (n *ElementDecl) Replace(nodes ...Node) error
- func (n *ElementDecl) SetLine(line int)
- func (n *ElementDecl) SetNextSibling(cur Node)
- func (n *ElementDecl) SetOwnerDocument(doc *Document)
- func (n *ElementDecl) SetParent(cur Node)
- func (n *ElementDecl) SetPrevSibling(cur Node)
- func (n *ElementDecl) SetTreeDoc(doc *Document)
- func (n ElementDecl) Type() ElementType
- type ElementType
- type Entity
- func (e *Entity) AddChild(cur Node) error
- func (n *Entity) AddNamespaceDecl(ns *Namespace)
- func (e *Entity) AddSibling(cur Node) error
- func (e *Entity) AppendText(b []byte) error
- func (e *Entity) Checked() bool
- func (e *Entity) Content() []byte
- func (n *Entity) DeclareNamespace(prefix, uri string) error
- func (e *Entity) EntityType() enum.EntityType
- func (e *Entity) ExternalID() string
- func (e *Entity) MarkChecked()
- func (n *Entity) Name() string
- func (n Entity) Namespace() *Namespace
- func (n Entity) Namespaces() []*Namespace
- func (n Entity) Prefix() string
- func (n *Entity) RemoveNamespaceByPrefix(prefix string) bool
- func (e *Entity) Replace(nodes ...Node) error
- func (n *Entity) SetActiveNamespace(prefix, uri string) error
- func (n *Entity) SetNs(ns *Namespace)
- func (e *Entity) SetOrig(s string)
- func (n *Entity) SetTreeDoc(doc *Document)
- func (e *Entity) SystemID() string
- func (e *Entity) URI() string
- type EntityRef
- func (e *EntityRef) AddChild(cur Node) error
- func (n *EntityRef) AddNamespaceDecl(ns *Namespace)
- func (e *EntityRef) AddSibling(cur Node) error
- func (e *EntityRef) AppendText(b []byte) error
- func (n *EntityRef) DeclareNamespace(prefix, uri string) error
- func (n *EntityRef) Name() string
- func (n EntityRef) Namespace() *Namespace
- func (n EntityRef) Namespaces() []*Namespace
- func (n EntityRef) Prefix() string
- func (n *EntityRef) RemoveNamespaceByPrefix(prefix string) bool
- func (e *EntityRef) Replace(nodes ...Node) error
- func (n *EntityRef) SetActiveNamespace(prefix, uri string) error
- func (n *EntityRef) SetNs(ns *Namespace)
- func (n *EntityRef) SetTreeDoc(doc *Document)
- func (n EntityRef) URI() string
- type Enumeration
- type ErrParseError
- type ErrorCollector
- type ErrorDomain
- type ErrorHandler
- type ErrorLevel
- type ErrorLeveler
- type LoadSubsetOption
- type LocalNamePredicate
- type MutableNode
- type NSPredicate
- type Namespace
- type NamespaceContainer
- type NamespaceNodeWrapper
- func (n *NamespaceNodeWrapper) Content() []byte
- func (n NamespaceNodeWrapper) FirstChild() Node
- func (n NamespaceNodeWrapper) LastChild() Node
- func (n NamespaceNodeWrapper) Line() int
- func (n NamespaceNodeWrapper) LocalName() string
- func (n NamespaceNodeWrapper) Name() string
- func (n NamespaceNodeWrapper) NextSibling() Node
- func (n NamespaceNodeWrapper) OwnerDocument() *Document
- func (n NamespaceNodeWrapper) Parent() Node
- func (n NamespaceNodeWrapper) PrevSibling() Node
- func (n *NamespaceNodeWrapper) SetLine(line int)
- func (n *NamespaceNodeWrapper) SetNextSibling(cur Node)
- func (n *NamespaceNodeWrapper) SetOwnerDocument(doc *Document)
- func (n *NamespaceNodeWrapper) SetParent(cur Node)
- func (n *NamespaceNodeWrapper) SetPrevSibling(cur Node)
- func (n NamespaceNodeWrapper) Type() ElementType
- type Namespacer
- type NilErrorHandler
- type Node
- type NodeWalker
- type NodeWalkerFunc
- type Notation
- func (n *Notation) AddChild(cur Node) error
- func (n *Notation) AddSibling(cur Node) error
- func (n *Notation) AppendText(b []byte) error
- func (n Notation) Content() []byte
- func (n Notation) FirstChild() Node
- func (n *Notation) Free()
- func (n Notation) LastChild() Node
- func (n Notation) Line() int
- func (n Notation) LocalName() string
- func (n Notation) Name() string
- func (n Notation) NextSibling() Node
- func (n Notation) OwnerDocument() *Document
- func (n Notation) Parent() Node
- func (n Notation) PrevSibling() Node
- func (n *Notation) Replace(nodes ...Node) error
- func (n *Notation) SetLine(line int)
- func (n *Notation) SetNextSibling(cur Node)
- func (n *Notation) SetOwnerDocument(doc *Document)
- func (n *Notation) SetParent(cur Node)
- func (n *Notation) SetPrevSibling(cur Node)
- func (n *Notation) SetTreeDoc(doc *Document)
- func (n Notation) Type() ElementType
- type Parser
- func (p Parser) AllowNetwork(v bool) Parser
- func (p Parser) BaseURI(uri string) Parser
- func (p Parser) BigLineNumbers(v bool) Parser
- func (p Parser) BlockXXE(v bool) Parser
- func (p Parser) Catalog(c CatalogResolver) Parser
- func (p Parser) CharBufferSize(size int) Parser
- func (p Parser) CleanNamespaces(v bool) Parser
- func (p Parser) CompactTextNodes(v bool) Parser
- func (p Parser) DefaultDTDAttributes(v bool) Parser
- func (p Parser) ErrorHandler(h ErrorHandler) Parser
- func (p Parser) FS(fsys fs.FS) Parser
- func (p Parser) FixBaseURIs(v bool) Parser
- func (p Parser) IgnoreEncoding(v bool) Parser
- func (p Parser) LenientXMLDecl(v bool) Parser
- func (p Parser) LoadExternalDTD(v bool) Parser
- func (p Parser) MaxDepth(depth int) Parser
- func (p Parser) MaxExternalDTDBytes(n int) Parser
- func (p Parser) MergeCDATA(v bool) Parser
- func (p Parser) NewPushParser(ctx context.Context) *PushParser
- func (p Parser) Parse(ctx context.Context, b []byte) (*Document, error)
- func (p Parser) ParseFile(ctx context.Context, path string) (*Document, error)
- func (p Parser) ParseInNodeContext(ctx context.Context, node Node, data []byte) (Node, error)
- func (p Parser) ParseReader(ctx context.Context, r io.Reader) (*Document, error)
- func (p Parser) PedanticErrors(v bool) Parser
- func (p Parser) ProcessXInclude(v bool) Parser
- func (p Parser) RecoverOnError(v bool) Parser
- func (p Parser) RelaxLimits(v bool) Parser
- func (p Parser) ReuseDict(v bool) Parser
- func (p Parser) SAXHandler(s sax.SAX2Handler) Parser
- func (p Parser) SkipIDs(v bool) Parser
- func (p Parser) StripBlanks(v bool) Parser
- func (p Parser) SubstituteEntities(v bool) Parser
- func (p Parser) SuppressErrors(v bool) Parser
- func (p Parser) SuppressWarnings(v bool) Parser
- func (p Parser) ValidateDTD(v bool) Parser
- func (p Parser) XIncludeNodes(v bool) Parser
- type ProcessingInstruction
- func (p *ProcessingInstruction) AddChild(cur Node) error
- func (p *ProcessingInstruction) AddSibling(cur Node) error
- func (p *ProcessingInstruction) AppendText(b []byte) error
- func (p *ProcessingInstruction) Content() []byte
- func (n ProcessingInstruction) FirstChild() Node
- func (n ProcessingInstruction) LastChild() Node
- func (n ProcessingInstruction) Line() int
- func (n ProcessingInstruction) LocalName() string
- func (p *ProcessingInstruction) Name() string
- func (n ProcessingInstruction) NextSibling() Node
- func (n ProcessingInstruction) OwnerDocument() *Document
- func (n ProcessingInstruction) Parent() Node
- func (n ProcessingInstruction) PrevSibling() Node
- func (p *ProcessingInstruction) Replace(nodes ...Node) error
- func (n *ProcessingInstruction) SetLine(line int)
- func (n *ProcessingInstruction) SetNextSibling(cur Node)
- func (n *ProcessingInstruction) SetOwnerDocument(doc *Document)
- func (n *ProcessingInstruction) SetParent(cur Node)
- func (n *ProcessingInstruction) SetPrevSibling(cur Node)
- func (p *ProcessingInstruction) SetTreeDoc(doc *Document)
- func (p *ProcessingInstruction) Type() ElementType
- type PushParser
- type QNamePredicate
- type SubstitutionType
- type Text
- func (n *Text) AddChild(cur Node) error
- func (n *Text) AddNamespaceDecl(ns *Namespace)
- func (n *Text) AddSibling(cur Node) error
- func (n *Text) AppendText(b []byte) error
- func (n Text) Content() []byte
- func (n *Text) DeclareNamespace(prefix, uri string) error
- func (n *Text) Name() string
- func (n Text) Namespace() *Namespace
- func (n Text) Namespaces() []*Namespace
- func (n Text) Prefix() string
- func (n *Text) RemoveNamespaceByPrefix(prefix string) bool
- func (n *Text) Replace(nodes ...Node) error
- func (n *Text) SetActiveNamespace(prefix, uri string) error
- func (n *Text) SetNs(ns *Namespace)
- func (n *Text) SetTreeDoc(doc *Document)
- func (n Text) URI() string
- type TreeBuilder
- func (t *TreeBuilder) AttributeDecl(ctxif context.Context, eName string, aName string, typ enum.AttributeType, ...) error
- func (t *TreeBuilder) CDataBlock(ctxif context.Context, data []byte) error
- func (t *TreeBuilder) Characters(ctxif context.Context, data []byte) error
- func (t *TreeBuilder) Comment(ctxif context.Context, data []byte) error
- func (t *TreeBuilder) ElementDecl(ctxif context.Context, name string, typ enum.ElementType, ...) error
- func (t *TreeBuilder) EndDTD(ctxif context.Context) error
- func (t *TreeBuilder) EndDocument(ctxif context.Context) error
- func (t *TreeBuilder) EndElementNS(ctxif context.Context, localname, prefix, uri string) error
- func (t *TreeBuilder) EndEntity(ctxif context.Context, name string) error
- func (t *TreeBuilder) EntityDecl(ctxif context.Context, name string, typ enum.EntityType, publicID string, ...) error
- func (t *TreeBuilder) Error(ctxif context.Context, err error) error
- func (t *TreeBuilder) ExternalEntityDecl(ctxif context.Context, name string, publicID string, systemID string) error
- func (t *TreeBuilder) ExternalSubset(ctxif context.Context, name, eid, uri string) error
- func (t *TreeBuilder) GetEntity(ctxif context.Context, name string) (ent sax.Entity, err error)
- func (t *TreeBuilder) GetExternalSubset(ctxif context.Context, name string, baseURI string) error
- func (t *TreeBuilder) GetParameterEntity(ctxif context.Context, name string) (sax.Entity, error)
- func (t *TreeBuilder) HasExternalSubset(ctxif context.Context) (bool, error)
- func (t *TreeBuilder) HasInternalSubset(ctxif context.Context) (bool, error)
- func (t *TreeBuilder) IgnorableWhitespace(ctxif context.Context, content []byte) error
- func (t *TreeBuilder) InternalEntityDecl(ctxif context.Context, name string, value string) error
- func (t *TreeBuilder) InternalSubset(ctxif context.Context, name, eid, uri string) error
- func (t *TreeBuilder) IsStandalone(ctxif context.Context) (bool, error)
- func (t *TreeBuilder) NotationDecl(ctxif context.Context, name string, publicID string, systemID string) error
- func (t *TreeBuilder) ProcessingInstruction(ctxif context.Context, target, data string) error
- func (t *TreeBuilder) Reference(ctxif context.Context, name string) error
- func (t *TreeBuilder) ResolveEntity(ctxif context.Context, publicID string, systemID string) (sax.ParseInput, error)
- func (t *TreeBuilder) SetDocumentLocator(ctxif context.Context, loc sax.DocumentLocator) error
- func (t *TreeBuilder) SkippedEntity(ctxif context.Context, name string) error
- func (t *TreeBuilder) StartDTD(ctxif context.Context, name string, publicID string, systemID string) error
- func (t *TreeBuilder) StartDocument(ctxif context.Context) error
- func (t *TreeBuilder) StartElementNS(ctxif context.Context, localname, prefix, uri string, ...) error
- func (t *TreeBuilder) StartEntity(ctxif context.Context, name string) error
- func (t *TreeBuilder) UnparsedEntityDecl(ctxif context.Context, name string, publicID string, systemID string, ...) error
- func (t *TreeBuilder) Warning(ctxif context.Context, err error) error
- type Writer
- func (w Writer) AllowPrefixUndeclarations(v bool) Writer
- func (w Writer) EscapeNonASCII(v bool) Writer
- func (w Writer) Format(v bool) Writer
- func (w Writer) IncludeDTD(v bool) Writer
- func (w Writer) IndentString(s string) Writer
- func (w Writer) SelfCloseEmptyElements(v bool) Writer
- func (d Writer) WriteTo(out io.Writer, node Node) error
- func (w Writer) XMLDeclaration(v bool) Writer
- type XIncludeMarker
- func (n *XIncludeMarker) AddChild(cur Node) error
- func (n *XIncludeMarker) AddNamespaceDecl(ns *Namespace)
- func (n *XIncludeMarker) AddSibling(cur Node) error
- func (n *XIncludeMarker) AppendText(b []byte) error
- func (n *XIncludeMarker) DeclareNamespace(prefix, uri string) error
- func (n *XIncludeMarker) Name() string
- func (n XIncludeMarker) Namespace() *Namespace
- func (n XIncludeMarker) Namespaces() []*Namespace
- func (n XIncludeMarker) Prefix() string
- func (n *XIncludeMarker) RemoveNamespaceByPrefix(prefix string) bool
- func (n *XIncludeMarker) Replace(nodes ...Node) error
- func (n *XIncludeMarker) SetActiveNamespace(prefix, uri string) error
- func (n *XIncludeMarker) SetNs(ns *Namespace)
- func (n *XIncludeMarker) SetTreeDoc(doc *Document)
- func (n XIncludeMarker) URI() string
Constants ¶
const ( StandaloneInvalidValue = -99 StandaloneExplicitYes = 1 StandaloneExplicitNo = 0 StandaloneNoXMLDecl = -1 StandaloneImplicitNo = -2 )
const MaxExternalDTDSize = 10 << 20 // 10 MiB
MaxExternalDTDSize is the maximum number of bytes read from an external DTD subset. Loading is gated by LoadExternalDTD/ValidateDTD/ DefaultDTDAttributes, so an unbounded read of a hostile or pathological source (e.g. /dev/zero) could exhaust memory before any entity or parse limits apply. The DTD is read through a strict byte cap and rejected when it is exceeded.
const MaxNameLength = 50000
Variables ¶
var ( EntityLT = newEntity("lt", enum.InternalPredefinedEntity, "", "", "<", "<") EntityGT = newEntity("gt", enum.InternalPredefinedEntity, "", "", ">", ">") EntityAmpersand = newEntity("amp", enum.InternalPredefinedEntity, "", "", "&", "&") EntityApostrophe = newEntity("apos", enum.InternalPredefinedEntity, "", "", "'", "'") EntityQuote = newEntity("quot", enum.InternalPredefinedEntity, "", "", `"`, """) )
var ( ErrNilNode = errors.New("nil node") ErrInvalidOperation = errors.New("operation cannot be performed") ErrDuplicateAttribute = errors.New("duplicate attribute") ErrEntityBoundary = errors.New("entity boundary violation") // ErrExternalDTDTooLarge is returned when an external DTD subset exceeds // the configured byte cap (set via Parser.MaxExternalDTDBytes), or // MaxExternalDTDSize when no cap is configured. The cap is enforced // against the actual number of bytes read, not any advisory Stat size. ErrExternalDTDTooLarge = errors.New("external DTD exceeds maximum allowed size") )
Sentinel errors for DOM operations.
var ( ErrAmpersandRequired = errors.New("'&' was required here") ErrAttrListNotFinished = errors.New("attrlist must finish with a ')'") ErrAttrListNotStarted = errors.New("attrlist must start with a '('") ErrAttributeNameRequired = errors.New("attribute name was required here (ATTLIST)") ErrByteCursorRequired = errors.New("inconsistent state: required ByteCursor") ErrDocTypeNameRequired = errors.New("doctype name required") ErrDocTypeNotFinished = errors.New("doctype not finished") ErrDocumentEnd = errors.New("extra content at document end") ErrEOF = errors.New("end of file reached") ErrElementContentNotFinished = errors.New("element content not finished") ErrEmptyDocument = errors.New("start tag expected, '<' not found") ErrEntityNotFound = errors.New("entity not found") ErrEqualSignRequired = errors.New("'=' was required here") ErrGtRequired = errors.New("'>' was required here") ErrHyphenInComment = errors.New("'--' not allowed in comment") ErrInvalidChar = errors.New("invalid char") ErrInvalidComment = errors.New("invalid comment section") ErrInvalidCDSect = errors.New("invalid CDATA section") ErrInvalidDocument = errors.New("invalid document") ErrInvalidDTD = errors.New("invalid DTD section") ErrInvalidElementDecl = errors.New("invalid element declaration") ErrInvalidEncodingName = errors.New("invalid encoding name") ErrInvalidName = errors.New("invalid xml name") ErrInvalidProcessingInstruction = errors.New("invalid processing instruction") ErrInvalidVersionNum = errors.New("invalid version") ErrInvalidXMLDecl = errors.New("invalid XML declaration") ErrInvalidParserCtx = errors.New("invalid parser context") ErrLtSlashRequired = errors.New("'</' is required") ErrMisplacedCDATAEnd = errors.New("misplaced CDATA end ']]>'") ErrNameTooLong = errors.New("name is too long") ErrNameRequired = errors.New("name is required") ErrNmtokenRequired = errors.New("nmtoken is required") ErrNotationNameRequired = errors.New("notation name expected in NOTATION declaration") ErrNotationNotFinished = errors.New("notation must finish with a ')'") ErrNotationNotStarted = errors.New("notation must start with a '('") ErrOpenParenRequired = errors.New("'(' is required") ErrPCDATARequired = errors.New("'#PCDATA' required") ErrPercentRequired = errors.New("'%' is required") ErrPrematureEOF = errors.New("end of document reached") ErrUndeclaredEntity = errors.New("undeclared entity") ErrSemicolonRequired = errors.New("';' is required") ErrConditionalSectionNotFinished = errors.New("conditional section ']]>' expected") ErrConditionalSectionKeyword = errors.New("INCLUDE or IGNORE keyword expected in conditional section") ErrSpaceRequired = errors.New("space required") ErrStartTagRequired = errors.New("start tag expected, '<' not found") ErrValueRequired = errors.New("value required") )
Sentinel errors for XML parse failures. Each corresponds to a specific syntactic violation detected by the parser. These errors typically appear as the Err field of an ErrParseError.
var ( ErrCDATANotFinished = errors.New("invalid CDATA section (premature end)") ErrCDATAInvalid = errors.New("invalid CDATA section") )
var ErrDTDValidationFailed = errors.New("dtd: validation failed")
ErrDTDValidationFailed is returned by DTD validation when the document does not conform to the DTD. Individual validation errors are delivered to the configured ErrorHandler.
var ErrParseSucceeded = errors.New("parse succeeded")
Functions ¶
func AppendChildFast ¶ added in v0.3.0
func AppendChildFast(parent MutableNode, child Node) error
AppendChildFast links child as the last child of parent without running the cycle-guard and duplicate-attribute preflight that AddChild performs. It is intended for callers that are building a freshly-constructed, provably acyclic and duplicate-free tree (e.g. a deep copy), where those safety checks are pure overhead. Misuse on an arbitrary live tree can corrupt linkage; prefer AddChild unless the no-preflight contract is known to hold.
func AsNode ¶
AsNode performs a safe type assertion on a Node, returning the concrete type T and true if the assertion succeeds, or the zero value of T and false otherwise.
if elem, ok := helium.AsNode[*helium.Element](node); ok {
// use elem
}
func BuildURI ¶
BuildURI resolves a relative system ID against a base URI. For local file paths (no scheme or file: scheme), it uses filepath.Join. For other schemes, it uses url.ResolveReference.
func ChildElements ¶
ChildElements returns an iterator over the direct child elements of n, skipping non-element children such as text, comments, and processing instructions. Use ChildElements when you only care about element children and want to avoid type-checking each node yourself.
To iterate over all child nodes including non-elements, use Children instead.
If n is nil or has no element children, the iterator yields nothing.
The caller must not modify the tree structure (add, remove, or reorder nodes) during iteration. Doing so may cause nodes to be skipped or visited more than once.
func Children ¶
Children returns an iterator over all direct child nodes of n, including elements, text, comments, processing instructions, and any other node types. Use Children when you need to inspect or process every node in the child list regardless of type.
To iterate over child elements only, use ChildElements instead.
If n is nil or has no children, the iterator yields nothing.
The caller must not modify the tree structure (add, remove, or reorder nodes) during iteration. Doing so may cause nodes to be skipped or visited more than once.
func ClarkName ¶
ClarkName returns the Clark notation "{uri}local" for a namespace URI and local name pair.
func CopyDTDInfo ¶
func CopyDTDInfo(src, dst *Document)
CopyDTDInfo copies DTD information (entities, notations, element/attribute declarations) from src to dst. This preserves unparsed entity information when creating document copies via xsl:copy.
func CopyExtSubset ¶ added in v0.3.0
func CopyExtSubset(src, dst *Document)
CopyExtSubset deep-copies src's external DTD subset into dst, installing it as dst's external subset. The copy is fully independent: it owns its own *DTD and its own entity/element/attribute/notation declarations, so mutating dst's external subset (e.g. via AddNotation/AddEntity/AddElementDecl) never affects src's external subset, and vice versa.
Unlike CopyDTDInfo (which copies the internal subset and links it into the document tree before the root element), the external subset is not a child of the document — it is referenced only via ExtSubset — so the copy is not added to dst's child list. If src has no external subset this is a no-op.
func Descendants ¶
Descendants returns an iterator that performs a depth-first pre-order traversal of all descendants of n (not including n itself). If n is nil or has no children, the iterator yields nothing.
The caller must not modify the tree structure (add, remove, or reorder nodes) during iteration. Doing so may cause nodes to be skipped or visited more than once.
func NewLeveledError ¶
func NewLeveledError(msg string, level ErrorLevel) error
NewLeveledError creates an error that implements ErrorLeveler.
func NodeGetBase ¶
NodeGetBase returns the effective base URI for a node by walking ancestors and resolving xml:base attributes. Returns empty string if no base URI found.
func SetNodeBaseURI ¶
SetNodeBaseURI sets an explicit base URI on a node. This is used by xsl:copy to preserve the original element's base URI on the copy.
func StopParser ¶
StopParser tells the parser to stop at the next opportunity. Call this from any SAX callback to abort parsing early. The parse functions will return the partial document built so far with a nil error.
func UnlinkNode ¶
func UnlinkNode(n MutableNode)
UnlinkNode detaches a node from its parent and sibling chain. After unlinking, the node has no parent, prev, or next pointers.
func Walk ¶
func Walk(n Node, w NodeWalker) error
Walk performs a depth-first traversal of the node tree rooted at n, calling w.Visit for each node. There is no direct libxml2 equivalent; callers typically write manual tree traversal loops in C.
func Write ¶
Write serializes a node (document or element) to the given writer using default settings.
func WriteString ¶
WriteString serializes a node (document or element) to a string using default settings.
Types ¶
type AttrNotFoundError ¶
type AttrNotFoundError struct {
Token string
}
AttrNotFoundError is returned when a referenced attribute token cannot be found in the DTD attribute declarations.
func (AttrNotFoundError) Error ¶
func (e AttrNotFoundError) Error() string
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
Attribute represents an XML attribute (libxml2: xmlAttr).
func (*Attribute) AType ¶
func (n *Attribute) AType() enum.AttributeType
AType returns the attribute type (e.g. enum.AttrID, enum.AttrCDATA).
func (*Attribute) AddChild ¶
AddChild adds cur as a child of this attribute node. For attributes the child is typically a text node holding the attribute value.
func (*Attribute) AddSibling ¶
AddSibling inserts cur as the next sibling of this attribute, effectively appending another attribute to the owning element's attribute list.
func (*Attribute) AppendText ¶
AppendText appends the given bytes to the attribute's text content.
func (Attribute) FirstChild ¶
func (n Attribute) FirstChild() Node
func (*Attribute) IsDefault ¶
IsDefault reports whether this attribute was supplied by the DTD as a default value rather than being explicitly specified in the source document.
func (Attribute) Name ¶
Name returns the qualified (prefixed) name of the attribute. If the attribute belongs to a namespace with a non-empty prefix, the result is "prefix:localname"; otherwise it is just the local name.
func (*Attribute) NextAttribute ¶
NextAttribute is a thin wrapper around NextSibling() so that the caller does not have to constantly type assert
func (Attribute) NextSibling ¶
func (n Attribute) NextSibling() Node
func (Attribute) OwnerDocument ¶
func (n Attribute) OwnerDocument() *Document
func (Attribute) Prefix ¶
Prefix returns the namespace prefix of the attribute, or an empty string if the attribute is not in a namespace.
func (Attribute) PrevSibling ¶
func (n Attribute) PrevSibling() Node
func (*Attribute) Replace ¶
Replace replaces this attribute node in its parent's attribute list with the given nodes.
func (*Attribute) SetAType ¶
func (n *Attribute) SetAType(v enum.AttributeType)
SetAType sets the attribute type.
func (*Attribute) SetDefault ¶
SetDefault marks (or unmarks) this attribute as a default attribute, i.e. one supplied by the DTD rather than present in the source document.
func (*Attribute) SetNextSibling ¶
func (n *Attribute) SetNextSibling(cur Node)
func (*Attribute) SetOwnerDocument ¶
func (n *Attribute) SetOwnerDocument(doc *Document)
func (*Attribute) SetPrevSibling ¶
func (n *Attribute) SetPrevSibling(cur Node)
func (*Attribute) SetTreeDoc ¶
SetTreeDoc recursively sets the owner document for this attribute and all of its children (e.g. its text-node value).
func (Attribute) Type ¶
func (n Attribute) Type() ElementType
type AttributeDecl ¶
type AttributeDecl struct {
// contains filtered or unexported fields
}
AttributeDecl is an xml attribute declaration from DTD.
func (*AttributeDecl) AType ¶
func (n *AttributeDecl) AType() enum.AttributeType
AType returns the attribute type (e.g. enum.AttrID, enum.AttrCDATA).
func (*AttributeDecl) AddChild ¶
func (n *AttributeDecl) AddChild(cur Node) error
AddChild adds cur as a child of this attribute declaration node.
func (*AttributeDecl) AddSibling ¶
func (n *AttributeDecl) AddSibling(cur Node) error
AddSibling inserts cur as the next sibling of this attribute declaration in the DTD's declaration list.
func (*AttributeDecl) AppendText ¶
func (n *AttributeDecl) AppendText(b []byte) error
AppendText appends the given bytes to this attribute declaration's text content.
func (*AttributeDecl) Elem ¶
func (n *AttributeDecl) Elem() string
Elem returns the element name this attribute declaration belongs to.
func (AttributeDecl) FirstChild ¶
func (n AttributeDecl) FirstChild() Node
func (AttributeDecl) NextSibling ¶
func (n AttributeDecl) NextSibling() Node
func (AttributeDecl) OwnerDocument ¶
func (n AttributeDecl) OwnerDocument() *Document
func (AttributeDecl) PrevSibling ¶
func (n AttributeDecl) PrevSibling() Node
func (*AttributeDecl) Replace ¶
func (n *AttributeDecl) Replace(nodes ...Node) error
Replace replaces this attribute declaration node with the given nodes.
func (*AttributeDecl) SetNextSibling ¶
func (n *AttributeDecl) SetNextSibling(cur Node)
func (*AttributeDecl) SetOwnerDocument ¶
func (n *AttributeDecl) SetOwnerDocument(doc *Document)
func (*AttributeDecl) SetPrevSibling ¶
func (n *AttributeDecl) SetPrevSibling(cur Node)
func (*AttributeDecl) SetTreeDoc ¶
func (n *AttributeDecl) SetTreeDoc(doc *Document)
SetTreeDoc recursively sets the owner document for this attribute declaration and all of its children.
func (AttributeDecl) Type ¶
func (n AttributeDecl) Type() ElementType
type AttributePredicate ¶
AttributePredicate reports whether an attribute matches a lookup. Implementations are used by FindAttribute to support alternate matching semantics without exposing the property list layout.
type CDATASection ¶
type CDATASection struct {
// contains filtered or unexported fields
}
CDATASection represents a CDATA section node in the DOM tree (libxml2: xmlNode with type XML_CDATA_SECTION_NODE).
func (*CDATASection) AddChild ¶
func (n *CDATASection) AddChild(cur Node) error
func (*CDATASection) AddNamespaceDecl ¶ added in v0.3.0
func (n *CDATASection) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*CDATASection) AddSibling ¶
func (n *CDATASection) AddSibling(cur Node) error
func (*CDATASection) AppendText ¶
func (n *CDATASection) AppendText(b []byte) error
func (CDATASection) Content ¶
func (n CDATASection) Content() []byte
Content returns a defensive copy of the CDATA section's content. Mutating the returned slice does NOT affect the node; re-reading returns the original bytes.
func (*CDATASection) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (CDATASection) Namespaces ¶
func (n CDATASection) Namespaces() []*Namespace
func (*CDATASection) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*CDATASection) Replace ¶
func (n *CDATASection) Replace(nodes ...Node) error
func (*CDATASection) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*CDATASection) SetNs ¶
func (n *CDATASection) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*CDATASection) SetTreeDoc ¶
func (n *CDATASection) SetTreeDoc(doc *Document)
type CatalogResolver ¶
type CatalogResolver interface {
// Resolve resolves a public/system identifier pair to a URI.
// Either pubID or sysID may be empty. Returns "" if no match is found.
Resolve(ctx context.Context, pubID, sysID string) string
// ResolveURI resolves a URI reference. Returns "" if no match is found.
ResolveURI(ctx context.Context, uri string) string
}
CatalogResolver resolves external entity identifiers and URIs via an XML catalog. Implementations are passed to Parser.Catalog to enable catalog-based resolution during parsing.
The github.com/lestrrat-go/helium/catalog package provides a standard implementation backed by OASIS XML Catalog files. Custom implementations may also be used.
type Comment ¶
type Comment struct {
// contains filtered or unexported fields
}
Comment represents an XML comment node (libxml2: xmlNode with type XML_COMMENT_NODE).
func (*Comment) AddNamespaceDecl ¶ added in v0.3.0
func (n *Comment) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*Comment) AddSibling ¶
AddSibling adds a new sibling to the end of the sibling nodes.
func (*Comment) AppendText ¶
func (Comment) Content ¶
Content returns a defensive copy of the comment's content. Mutating the returned slice does NOT affect the node; re-reading returns the original bytes.
func (*Comment) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (Comment) Namespaces ¶
func (n Comment) Namespaces() []*Namespace
func (*Comment) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*Comment) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*Comment) SetNs ¶
func (n *Comment) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*Comment) SetTreeDoc ¶
type DTD ¶
type DTD struct {
// contains filtered or unexported fields
}
DTD represents an XML Document Type Definition (libxml2: xmlDtd).
func (*DTD) AddChild ¶
AddChild appends cur as the last child of the DTD, detaching it from any previous parent first. It returns an error if cur is nil or if the insertion would create a cycle.
func (*DTD) AddElementDecl ¶
func (dtd *DTD) AddElementDecl(name string, typ enum.ElementType, content *ElementContent) (*ElementDecl, error)
AddElementDecl declares an element content model in the DTD and registers it as a child node. The name may be a QName; its prefix is split off for keying. content must be nil for EMPTY/ANY element types and non-nil for MIXED/ELEMENT types. A previously undefined declaration (created when one of the element's attributes was declared first) is completed in place; a second concrete declaration of the same element is an error.
func (*DTD) AddEntity ¶
func (dtd *DTD) AddEntity(name string, typ enum.EntityType, publicID, systemID, content string) (*Entity, error)
AddEntity declares an entity in the DTD and registers it as a child node, routing general entities and parameter entities into their respective tables based on typ. Predefined entities cannot be registered, and an unknown typ is rejected. Redeclaring an existing general/parameter entity is a no-op that returns the existing declaration (first definition wins, per XML §4.2); redeclaring a predefined entity (lt, gt, amp, apos, quot) with content that does not resolve to the same character is an error.
func (*DTD) AddNotation ¶
AddNotation declares a notation in the DTD and registers it as a child node. It returns an error if a notation with the same name is already declared.
func (*DTD) AddSibling ¶
AddSibling appends cur as the last sibling of the DTD.
func (*DTD) AppendText ¶
AppendText appends b as a Text child of the DTD.
func (*DTD) AttributesForElement ¶
func (dtd *DTD) AttributesForElement(elem string) []*AttributeDecl
AttributesForElement returns all attribute declarations for the named element.
func (*DTD) ExternalID ¶
ExternalID returns the DTD external ID (PUBLIC identifier).
func (DTD) FirstChild ¶
func (n DTD) FirstChild() Node
func (*DTD) ForEachEntity ¶
ForEachEntity calls fn for every general entity declared in the DTD. The iteration order is unspecified.
func (*DTD) GetElementDesc ¶
func (dtd *DTD) GetElementDesc(name string) (*ElementDecl, bool)
GetElementDesc returns the element declaration for the given QName, splitting off any prefix to compose the lookup key, and reports whether it was found.
func (*DTD) LookupAttribute ¶
func (dtd *DTD) LookupAttribute(name, prefix, elem string) (*AttributeDecl, bool)
LookupAttribute returns the attribute declaration registered for the given attribute local name, prefix, and owning element name, and reports whether it was found.
func (*DTD) LookupElement ¶
func (dtd *DTD) LookupElement(name, prefix string) (*ElementDecl, bool)
LookupElement returns the element declaration registered under the given local name and prefix, and reports whether it was found.
func (*DTD) LookupEntity ¶
LookupEntity returns the general entity declared under name, and reports whether it was found.
func (*DTD) LookupNotation ¶
LookupNotation returns the notation declared under name, and reports whether it was found.
func (*DTD) LookupParameterEntity ¶
LookupParameterEntity returns the parameter entity declared under name, and reports whether it was found.
func (DTD) NextSibling ¶
func (n DTD) NextSibling() Node
func (DTD) OwnerDocument ¶
func (n DTD) OwnerDocument() *Document
func (DTD) PrevSibling ¶
func (n DTD) PrevSibling() Node
func (*DTD) RegisterAttribute ¶
func (dtd *DTD) RegisterAttribute(attr *AttributeDecl) error
RegisterAttribute records an attribute declaration in the DTD, keyed by its name, prefix, and owning element. It returns an error if an attribute with the same key is already declared.
func (*DTD) RemoveElement ¶
RemoveElement deletes the element declaration registered under the given local name and prefix, if present.
func (*DTD) SetNextSibling ¶
func (n *DTD) SetNextSibling(cur Node)
func (*DTD) SetOwnerDocument ¶
func (n *DTD) SetOwnerDocument(doc *Document)
func (*DTD) SetPrevSibling ¶
func (n *DTD) SetPrevSibling(cur Node)
func (*DTD) SetTreeDoc ¶
SetTreeDoc sets the owning document of the DTD and its subtree.
func (DTD) Type ¶
func (n DTD) Type() ElementType
type DTDDupTokenError ¶
type DTDDupTokenError struct {
Name string
}
DTDDupTokenError is returned when a DTD attribute enumeration contains a duplicate token value.
func (DTDDupTokenError) Error ¶
func (e DTDDupTokenError) Error() string
Error returns the diagnostic message for this duplicate token error.
type DocProperties ¶
type DocProperties int
DocProperties is a bitmask of document properties, mirroring libxml2's xmlDocProperties. Properties are set by the parser or by user code to record how the document was produced and what validations it passed.
const ( DocWellFormed DocProperties = 1 << iota // document is XML well-formed DocNSValid // document is namespace-valid DocOld10 // parsed with XML 1.0 (4th edition or earlier) DocDTDValid // DTD validation was successful DocXInclude // XInclude substitution was done DocUserBuilt // built via API, not by parsing DocInternal // built for internal processing DocHTML // parsed or built as HTML )
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document represents an XML document (libxml2: xmlDoc).
func NewDefaultDocument ¶
func NewDefaultDocument() *Document
NewDefaultDocument creates a minimal user-built document with version "1.0", no encoding, and implicit-no standalone (libxml2: xmlNewDoc).
func NewDocument ¶
func NewDocument(version, encoding string, standalone DocumentStandaloneType) *Document
NewDocument allocates an empty XML Document with the given XML declaration version, character encoding, and standalone status. The returned document owns no children yet; use CreateElement and the other Create* methods to build a tree, then attach the root via AddChild.
func NewHTMLDocument ¶
func NewHTMLDocument() *Document
NewHTMLDocument creates a new HTML document (HTMLDocumentNode type).
func (*Document) AddChild ¶
AddChild appends cur as the last child of the document, detaching it from any previous parent first. It returns an error if cur is nil or if the insertion would create a cycle.
func (*Document) AddSibling ¶
func (*Document) AppendText ¶
AppendText appends b as a Text child of the document, merging into a trailing Text node when possible.
func (*Document) CreateAttribute ¶
func (*Document) CreateCDATASection ¶
func (d *Document) CreateCDATASection(value []byte) *CDATASection
CreateCDATASection mirrors xmlNewCDataBlock in libxml2's tree.c.
func (*Document) CreateComment ¶
CreateComment allocates a new Comment node holding value, owned by this document, without attaching it to the tree.
func (*Document) CreateElement ¶
CreateElement allocates a new Element named name and owned by this document, but does not attach it to the tree; the caller must insert it via AddChild or a sibling/parent method. When d is non-nil the element is drawn from the document's slab allocator, so the element must not outlive a call to Document.Free. A nil receiver allocates a standalone element with no owning document.
func (*Document) CreateElementContent ¶
func (d *Document) CreateElementContent(name string, etype ElementContentType) (*ElementContent, error)
CreateElementContent builds an ElementContent node of the given type for use in a DTD content model. It returns an error if name and etype are not a valid combination.
func (*Document) CreateInternalSubset ¶
func (*Document) CreateNamespace ¶
func (*Document) CreatePI ¶
func (d *Document) CreatePI(target, data string) *ProcessingInstruction
func (*Document) CreateReference ¶
func (*Document) CreateText ¶
CreateText allocates a new Text node holding a copy of value, owned by this document, without attaching it to the tree. When d is non-nil both the node and its content bytes come from the document's slab allocators and must not outlive a call to Document.Free. A nil receiver allocates a standalone text node.
func (*Document) DocumentElement ¶
DocumentElement returns the root element of the document, or nil if none exists.
func (Document) FirstChild ¶
func (n Document) FirstChild() Node
func (*Document) Free ¶
func (d *Document) Free()
Free returns pooled slab chunks for reuse by future parse calls. This is optional — if not called, GC handles cleanup normally. Calling Free on a document that is still in use causes undefined behavior.
func (*Document) GetElementByID ¶
GetElementByID returns the first element in the document whose ID matches the given value. If the document's ID table has been populated (during parsing), it performs an O(1) hash lookup. Otherwise it falls back to an O(n) tree walk checking xml:id and DTD-declared ID attributes.
The ID-skip state (see SetSkipIDs) is authoritative and is checked FIRST: a document with SkipIDs() == true resolves NO ids — it returns nil without consulting the ID table or performing the lazy walk. This keeps GetElementByID and fn:id consistent with the SkipIDs contract even on a document that already has a populated ID table (e.g. one parsed normally and then SetSkipIDs(true)).
func (*Document) GetEntity ¶
GetEntity looks up a general entity declaration by name, searching the internal subset first and then the external subset (the latter is skipped for standalone="yes" documents). found reports whether a declaration was located.
func (*Document) GetParameterEntity ¶
GetParameterEntity looks up a parameter entity declaration by name, searching the internal subset first and then the external subset (the latter is skipped for standalone="yes" documents). The boolean result reports whether a declaration was located.
func (*Document) HasProperty ¶
func (d *Document) HasProperty(p DocProperties) bool
HasProperty reports whether all bits in p are set.
func (*Document) IDTable ¶ added in v0.3.0
IDTable returns the document's ID->element table populated during parsing (mirroring libxml2's xmlAddID). The returned map is the document's own, not a copy, and is nil for documents built without an interned ID table (e.g. via the API rather than the parser); callers must not mutate it. It lets a derived document (e.g. an xsl:strip-space copy) rebuild an equivalent table by translating each entry's element through the original->copy correspondence, faithfully preserving id()/GetElementByID semantics — including for prefixed elements whose qualified DTD ATTLIST the lazy GetElementByID fallback would otherwise miss.
func (*Document) InternalSubset ¶
func (*Document) IsMixedElement ¶
IsMixedElement reports whether the element named name is declared with mixed (or EMPTY/ANY) content in the document's internal subset. It returns an error if no element declaration is found for name.
func (Document) NextSibling ¶
func (n Document) NextSibling() Node
func (Document) OwnerDocument ¶
func (n Document) OwnerDocument() *Document
func (Document) PrevSibling ¶
func (n Document) PrevSibling() Node
func (*Document) Properties ¶
func (d *Document) Properties() DocProperties
Properties returns the document's property flags.
func (*Document) RawEncoding ¶ added in v0.3.0
RawEncoding returns the document's encoding exactly as recorded, WITHOUT the "utf8" default that Encoding() synthesizes for documents whose XML declaration omitted an encoding. An empty result means the source had no encoding declaration. This is the value the XML serializer consults (it emits encoding="..." only when the raw encoding is non-empty), so a faithful copy of a document — e.g. an xsl:strip-space copy — must propagate this rather than Encoding(), which would synthesize a spurious encoding="utf8".
func (*Document) RegisterID ¶
RegisterID associates an ID value with an element in the document's ID table. This is called during parsing to build an O(1) lookup table for GetElementByID, mirroring libxml2's xmlAddID.
func (*Document) SetDocumentElement ¶
func (d *Document) SetDocumentElement(root MutableNode) error
func (*Document) SetEncoding ¶
func (*Document) SetNextSibling ¶
func (n *Document) SetNextSibling(cur Node)
func (*Document) SetOwnerDocument ¶
func (n *Document) SetOwnerDocument(doc *Document)
func (*Document) SetPrevSibling ¶
func (n *Document) SetPrevSibling(cur Node)
func (*Document) SetProperties ¶
func (d *Document) SetProperties(p DocProperties)
SetProperties replaces the document's property flags.
func (*Document) SetSkipIDs ¶ added in v0.3.0
SetSkipIDs sets the document's ID-skip state. This is used when producing a derived document (e.g. an xsl:strip-space copy) that must mirror the source's ID semantics.
The ID-skip state is authoritative: while it is true, GetElementByID (and therefore fn:id) resolves NO ids and returns nil — even if the document already has a populated ID table from a normal parse. Setting it back to false restores normal resolution against the existing table (or the lazy tree walk for API-built documents).
func (*Document) SetTreeDoc ¶
func (*Document) SkipIDs ¶ added in v0.3.0
SkipIDs reports whether ID attribute interning was skipped when this document was produced (mirrors the parser's SkipIDs option). When true, GetElementByID and fn:id always return no match without an O(n) tree walk.
func (*Document) Standalone ¶
func (d *Document) Standalone() DocumentStandaloneType
func (Document) Type ¶
func (n Document) Type() ElementType
type DocumentStandaloneType ¶
type DocumentStandaloneType int
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents an XML element node (libxml2: xmlNode with type XML_ELEMENT_NODE).
func (*Element) AddChild ¶
AddChild adds a new child node to the end of the children nodes (libxml2: xmlAddChild).
func (*Element) AddNamespaceDecl ¶ added in v0.3.0
func (n *Element) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*Element) AddSibling ¶
AddSibling adds a new sibling to the end of the sibling nodes (libxml2: xmlAddSibling).
func (*Element) AppendText ¶
AppendText appends text content to this node (libxml2: xmlNodeAddContent).
func (Element) Attributes ¶
Attributes returns a newly allocated slice of the element's attributes in property order. The returned slice is a snapshot: appending to or reordering it does not affect the element, though the *Attribute elements still point at the live attribute nodes. Use ForEachAttribute to avoid the slice allocation.
func (*Element) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (*Element) FindAttribute ¶
func (n *Element) FindAttribute(ap AttributePredicate) (*Attribute, bool)
FindAttribute returns the first attribute that matches ap in property order. A nil predicate matches nothing and returns nil, false.
func (Element) ForEachAttribute ¶
ForEachAttribute calls fn for each attribute on the element. If fn returns false, iteration stops early. This avoids the slice allocation of Attributes().
No dedicated unit tests: iteration order and early-stop semantics are exercised transitively by XPath attribute-axis and doc-order tests. All current callers always return true; the early-stop path exists as a natural consequence of the iterator pattern.
The unchecked type assertion on NextSibling is safe: the properties chain is attribute-only by construction (field typed *Attribute, only *Attribute nodes are ever linked in).
func (*Element) GetAttribute ¶
GetAttribute returns the value of the attribute with the given QName, or empty string and false if not found.
func (*Element) GetAttributeNS ¶
GetAttributeNS returns the value of the attribute with the given local name and namespace URI, or empty string and false if not found.
func (*Element) GetAttributeNodeNS ¶
GetAttributeNodeNS returns the Attribute node with the given local name and namespace URI, or nil if not found. This is the equivalent of libxml2's xmlHasNsProp, returning the node itself for further inspection (e.g., checking atype or whether it is a default attribute).
func (*Element) HasAttribute ¶
HasAttribute reports whether the element has an attribute with the given name.
func (Element) Namespaces ¶
func (n Element) Namespaces() []*Namespace
func (*Element) RemoveAttribute ¶
RemoveAttribute removes the attribute with the given QName from the element. Returns true if an attribute was removed.
func (*Element) RemoveAttributeNS ¶
RemoveAttributeNS removes the attribute with the given local name and namespace URI. Returns true if an attribute was removed.
func (*Element) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*Element) Replace ¶
Replace swaps this element out of its parent, inserting nodes in its place (libxml2: xmlReplaceNode). It returns an error if any operand is nil.
func (*Element) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*Element) SetAttribute ¶
SetAttribute creates or replaces the attribute named name, parsing value for entity references, and returns the element for chaining. The name must not contain a colon; use SetAttributeNS for namespaced attributes.
func (*Element) SetAttributeNS ¶
SetAttributeNS creates an attribute with the given local name, value, and namespace.
func (*Element) SetBooleanAttribute ¶
SetBooleanAttribute creates a boolean attribute (name only, no value). The attribute has no children, distinguishing it from an attribute with an empty string value.
func (*Element) SetLiteralAttribute ¶
SetLiteralAttribute creates or replaces an attribute with a literal text value. Unlike SetAttribute, the value is not parsed for entity references. This is useful for HTML where the parser has already resolved entities. An empty value creates a text child with empty content (distinguishing it from a boolean attribute which has no children).
func (*Element) SetLiteralAttributeNS ¶
SetLiteralAttributeNS creates or replaces an attribute with a literal text value and namespace. Unlike SetAttributeNS, the value is not parsed for entity references. This is useful when the parser has already resolved entities in attribute values.
func (*Element) SetNs ¶
func (n *Element) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*Element) SetTreeDoc ¶
SetTreeDoc sets the owning document of this element and of every node in its subtree (libxml2: xmlSetTreeDoc).
type ElementContent ¶
type ElementContent struct {
// contains filtered or unexported fields
}
ElementContent represents the content model of a DTD element declaration as a binary tree. Leaf nodes are either #PCDATA or named element references; interior nodes are sequence (,) or choice (|) operators. Each node carries an occurrence constraint (once, ?, *, +).
For example, the declaration <!ELEMENT doc (a, (b | c)+)> produces a sequence node at the root with element "a" as c1 and a choice node (b | c, occurrence +) as c2.
type ElementContentOccur ¶
type ElementContentOccur int
ElementContentOccur describes the occurrence constraint on an ElementContent node.
const ( // ElementContentOnce means the content must appear exactly once. ElementContentOnce ElementContentOccur = iota + 1 // ElementContentOpt means the content is optional (?). ElementContentOpt // ElementContentMult means the content may appear zero or more times (*). ElementContentMult // ElementContentPlus means the content must appear one or more times (+). ElementContentPlus )
type ElementContentType ¶
type ElementContentType int
ElementContentType describes the kind of node in an ElementContent tree.
const ( // ElementContentPCDATA indicates a #PCDATA leaf. ElementContentPCDATA ElementContentType = iota + 1 // ElementContentElement indicates a named element reference leaf. ElementContentElement // ElementContentSeq indicates a sequence (,) node with two children. ElementContentSeq // ElementContentOr indicates a choice (|) node with two children. ElementContentOr )
type ElementDecl ¶
type ElementDecl struct {
// contains filtered or unexported fields
}
ElementDecl is an xml element declaration from DTD.
func (*ElementDecl) AddChild ¶
func (n *ElementDecl) AddChild(cur Node) error
AddChild adds cur as a child of this element declaration node.
func (*ElementDecl) AddSibling ¶
func (n *ElementDecl) AddSibling(cur Node) error
AddSibling inserts cur as the next sibling of this element declaration in the DTD's declaration list.
func (*ElementDecl) AppendText ¶
func (n *ElementDecl) AppendText(b []byte) error
AppendText appends the given bytes to this element declaration's text content.
func (*ElementDecl) DeclType ¶
func (e *ElementDecl) DeclType() enum.ElementType
DeclType returns the element content type declared in the DTD (e.g., ElementElementType for element-only content).
func (ElementDecl) FirstChild ¶
func (n ElementDecl) FirstChild() Node
func (ElementDecl) NextSibling ¶
func (n ElementDecl) NextSibling() Node
func (ElementDecl) OwnerDocument ¶
func (n ElementDecl) OwnerDocument() *Document
func (ElementDecl) PrevSibling ¶
func (n ElementDecl) PrevSibling() Node
func (*ElementDecl) Replace ¶
func (n *ElementDecl) Replace(nodes ...Node) error
Replace replaces this element declaration node with the given nodes.
func (*ElementDecl) SetNextSibling ¶
func (n *ElementDecl) SetNextSibling(cur Node)
func (*ElementDecl) SetOwnerDocument ¶
func (n *ElementDecl) SetOwnerDocument(doc *Document)
func (*ElementDecl) SetPrevSibling ¶
func (n *ElementDecl) SetPrevSibling(cur Node)
func (*ElementDecl) SetTreeDoc ¶
func (n *ElementDecl) SetTreeDoc(doc *Document)
SetTreeDoc recursively sets the owner document for this element declaration and all of its children.
func (ElementDecl) Type ¶
func (n ElementDecl) Type() ElementType
type ElementType ¶
type ElementType int
const ( ElementNode ElementType = iota + 1 AttributeNode TextNode CDATASectionNode EntityRefNode EntityNode ProcessingInstructionNode CommentNode DocumentNode DocumentTypeNode DocumentFragNode NotationNode HTMLDocumentNode DTDNode ElementDeclNode AttributeDeclNode EntityDeclNode NamespaceDeclNode XIncludeStartNode XIncludeEndNode // NamespaceNode represents a namespace declaration (does not exist in libxml2). NamespaceNode )
func (ElementType) String ¶
func (i ElementType) String() string
type Entity ¶
type Entity struct {
// contains filtered or unexported fields
}
Entity represents an XML entity declaration (libxml2: xmlEntity).
func (*Entity) AddNamespaceDecl ¶ added in v0.3.0
func (n *Entity) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*Entity) AddSibling ¶
func (*Entity) AppendText ¶
func (*Entity) Checked ¶
Checked reports whether this entity's content has been parsed and validated, used to prevent infinite recursion during entity expansion (libxml2: ent->checked).
func (*Entity) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (*Entity) EntityType ¶
func (e *Entity) EntityType() enum.EntityType
func (*Entity) ExternalID ¶
func (*Entity) MarkChecked ¶
func (e *Entity) MarkChecked()
MarkChecked marks this entity as having been parsed and validated (libxml2: ent->checked).
func (Entity) Namespaces ¶
func (n Entity) Namespaces() []*Namespace
func (*Entity) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*Entity) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*Entity) SetNs ¶
func (n *Entity) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*Entity) SetTreeDoc ¶
type EntityRef ¶
type EntityRef struct {
// contains filtered or unexported fields
}
EntityRef represents an entity reference node in the DOM tree (libxml2: xmlNode with type XML_ENTITY_REF_NODE).
func (*EntityRef) AddNamespaceDecl ¶ added in v0.3.0
func (n *EntityRef) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*EntityRef) AddSibling ¶
func (*EntityRef) AppendText ¶
func (*EntityRef) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (EntityRef) Namespaces ¶
func (n EntityRef) Namespaces() []*Namespace
func (*EntityRef) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*EntityRef) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*EntityRef) SetNs ¶
func (n *EntityRef) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*EntityRef) SetTreeDoc ¶
type Enumeration ¶
type Enumeration []string
type ErrParseError ¶
type ErrParseError struct {
Column int
Domain ErrorDomain
Err error
File string
Level ErrorLevel
Line string
LineNumber int
}
ErrParseError is a structured parse error carrying the source location, context line, severity, and the underlying error. Use ErrParseError.FormatError to produce a libxml2-compatible multi-line diagnostic string. The error can be unwrapped via ErrParseError.Unwrap to access the underlying cause.
func (ErrParseError) Error ¶
func (e ErrParseError) Error() string
Error returns a human-readable string including the file, line, column, and a context snippet showing approximately where the error occurred.
func (ErrParseError) ErrorLevel ¶
func (e ErrParseError) ErrorLevel() ErrorLevel
ErrorLevel returns the severity of this parse error, satisfying the ErrorLeveler interface.
func (ErrParseError) FormatError ¶
func (e ErrParseError) FormatError() string
FormatError returns a libxml2-compatible multi-line error string:
FILE:LINE: DOMAIN SEVERITY : MESSAGE
CONTEXT_LINE
^
type ErrorCollector ¶
type ErrorCollector struct {
// contains filtered or unexported fields
}
ErrorCollector collects errors into a slice via an internal Sink[error]. When level is zero (ErrorLevelNone), all errors are collected. When set, only errors matching that level are collected.
Satisfies ErrorHandler and io.Closer. The parser/compiler closes it automatically at the end of the operation.
func NewErrorCollector ¶
func NewErrorCollector(ctx context.Context, level ErrorLevel, opts ...sink.Option) *ErrorCollector
NewErrorCollector creates an ErrorCollector backed by a Sink[error]. Pass ErrorLevelNone (0) for level to collect all errors regardless of severity.
func (*ErrorCollector) Close ¶
func (ec *ErrorCollector) Close() error
Close satisfies io.Closer. Drains the internal Sink.
func (*ErrorCollector) Errors ¶
func (ec *ErrorCollector) Errors() []error
Errors returns a copy of the collected errors. Safe to call after Close.
type ErrorDomain ¶
type ErrorDomain int
ErrorDomain classifies the subsystem that produced an error.
const ( // ErrorDomainParser indicates the error originated in the XML parser. ErrorDomainParser ErrorDomain = iota // ErrorDomainNamespace indicates the error originated in namespace // processing. ErrorDomainNamespace )
type ErrorHandler ¶
ErrorHandler receives errors reported during parsing, compilation, or validation. Implementations may log, accumulate, or discard errors.
Handle is called synchronously at the point of error detection unless the implementation itself introduces asynchrony (e.g. Sink[error]).
Implementations must not block for extended periods.
The error value may optionally implement ErrorLeveler to indicate severity. Users can type-assert to inspect the level.
type ErrorLevel ¶
type ErrorLevel int
ErrorLevel represents the severity of a parse error.
const ( // ErrorLevelNone indicates no specific severity. When used with // [NewErrorCollector], it means all errors are collected regardless // of level. ErrorLevelNone ErrorLevel = iota // ErrorLevelWarning indicates a non-fatal condition that may still // produce correct output. ErrorLevelWarning // ErrorLevelError indicates a recoverable error in the input. ErrorLevelError // ErrorLevelFatal indicates an unrecoverable error that stops processing. ErrorLevelFatal )
type ErrorLeveler ¶
type ErrorLeveler interface {
ErrorLevel() ErrorLevel
}
ErrorLeveler is an optional interface that errors can implement to report their severity. Errors that do not implement this interface are treated as warnings (ErrorLevelWarning).
type LoadSubsetOption ¶
type LoadSubsetOption int
const ( DetectIDs LoadSubsetOption = 1 << (iota + 1) CompleteAttrs // 4 SkipIDs // 8 )
func (LoadSubsetOption) IsSet ¶
func (p LoadSubsetOption) IsSet(n LoadSubsetOption) bool
func (*LoadSubsetOption) Set ¶
func (p *LoadSubsetOption) Set(n LoadSubsetOption)
type LocalNamePredicate ¶
type LocalNamePredicate string
LocalNamePredicate matches an attribute by local name only. If multiple attributes share the same local name, FindAttribute returns the first match in property order.
func (LocalNamePredicate) Match ¶
func (p LocalNamePredicate) Match(a *Attribute) bool
type MutableNode ¶
type MutableNode interface {
Node
AddChild(Node) error
AddSibling(Node) error
// AppendText appends text content to this node (libxml2: xmlNodeAddContent).
AppendText([]byte) error
Replace(...Node) error
SetLine(int)
SetNextSibling(Node)
SetOwnerDocument(doc *Document)
SetParent(Node)
SetPrevSibling(Node)
SetTreeDoc(doc *Document)
}
MutableNode extends Node with tree-mutation operations.
type NSPredicate ¶
NSPredicate matches an attribute by local name + namespace URI.
func (NSPredicate) Match ¶
func (p NSPredicate) Match(a *Attribute) bool
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace represents an XML namespace declaration (libxml2: xmlNs).
func LookupNSByHref ¶
LookupNSByHref walks the element and its ancestors to find a namespace declaration matching the given URI.
func LookupNSByPrefix ¶
LookupNSByPrefix walks the element and its ancestors to find a namespace declaration matching the given prefix. The "xml" prefix is always implicitly bound to the XML namespace.
func NewNamespace ¶
NewNamespace creates a new Namespace with the given prefix and URI.
type NamespaceContainer ¶
type NamespaceContainer interface {
Namespaces() []*Namespace
}
NamespaceContainer is an interface for nodes that carry namespace declarations.
type NamespaceNodeWrapper ¶
type NamespaceNodeWrapper struct {
// contains filtered or unexported fields
}
NamespaceNodeWrapper wraps a Namespace to implement the Node interface for XPath namespace axis traversal. In XPath, namespace nodes appear as nodes with a name (the prefix), content (the URI), and a parent (the owning element).
func NewNamespaceNodeWrapper ¶
func NewNamespaceNodeWrapper(ns *Namespace, owner Node) *NamespaceNodeWrapper
NewNamespaceNodeWrapper creates a Node that wraps a Namespace for XPath use.
func (*NamespaceNodeWrapper) Content ¶
func (n *NamespaceNodeWrapper) Content() []byte
func (NamespaceNodeWrapper) FirstChild ¶
func (n NamespaceNodeWrapper) FirstChild() Node
func (NamespaceNodeWrapper) NextSibling ¶
func (n NamespaceNodeWrapper) NextSibling() Node
func (NamespaceNodeWrapper) OwnerDocument ¶
func (n NamespaceNodeWrapper) OwnerDocument() *Document
func (NamespaceNodeWrapper) PrevSibling ¶
func (n NamespaceNodeWrapper) PrevSibling() Node
func (*NamespaceNodeWrapper) SetNextSibling ¶
func (n *NamespaceNodeWrapper) SetNextSibling(cur Node)
func (*NamespaceNodeWrapper) SetOwnerDocument ¶
func (n *NamespaceNodeWrapper) SetOwnerDocument(doc *Document)
func (*NamespaceNodeWrapper) SetPrevSibling ¶
func (n *NamespaceNodeWrapper) SetPrevSibling(cur Node)
func (NamespaceNodeWrapper) Type ¶
func (n NamespaceNodeWrapper) Type() ElementType
type Namespacer ¶
type Namespacer interface {
Namespace() *Namespace
Namespaces() []*Namespace
Prefix() string
URI() string
LocalName() string
}
Namespacer is an interface for things that have a namespace prefix and URI.
type NilErrorHandler ¶
type NilErrorHandler struct{}
NilErrorHandler is an ErrorHandler that discards all errors. Use as a default when no handler is provided.
type Node ¶
type Node interface {
Content() []byte
FirstChild() Node
LastChild() Node
Line() int
Name() string
NextSibling() Node
OwnerDocument() *Document
Parent() Node
PrevSibling() Node
Type() ElementType
// contains filtered or unexported methods
}
Node is a read-only view of an XML document tree node (libxml2: xmlNode).
type NodeWalker ¶
NodeWalker visits nodes during tree traversal.
type NodeWalkerFunc ¶
NodeWalkerFunc is an adapter to allow use of ordinary functions as NodeWalker. Similar to http.HandlerFunc.
func (NodeWalkerFunc) Visit ¶
func (f NodeWalkerFunc) Visit(n Node) error
type Notation ¶
type Notation struct {
// contains filtered or unexported fields
}
Notation is a notation declaration from a DTD.
func (*Notation) AddSibling ¶
AddSibling appends cur as the last sibling of the notation node.
func (*Notation) AppendText ¶
AppendText appends b as a Text child of the notation node.
func (Notation) FirstChild ¶
func (n Notation) FirstChild() Node
func (*Notation) Free ¶
func (n *Notation) Free()
Free is a no-op; it exists to satisfy the Node interface.
func (Notation) NextSibling ¶
func (n Notation) NextSibling() Node
func (Notation) OwnerDocument ¶
func (n Notation) OwnerDocument() *Document
func (Notation) PrevSibling ¶
func (n Notation) PrevSibling() Node
func (*Notation) Replace ¶
Replace swaps the notation node out of its parent, inserting nodes in its place.
func (*Notation) SetNextSibling ¶
func (n *Notation) SetNextSibling(cur Node)
func (*Notation) SetOwnerDocument ¶
func (n *Notation) SetOwnerDocument(doc *Document)
func (*Notation) SetPrevSibling ¶
func (n *Notation) SetPrevSibling(cur Node)
func (*Notation) SetTreeDoc ¶
SetTreeDoc sets the owning document of the notation node and its subtree.
func (Notation) Type ¶
func (n Notation) Type() ElementType
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser holds configuration for XML parsing (libxml2: xmlParserCtxt). It uses clone-on-write semantics: each builder method returns a new Parser sharing the underlying config until mutation.
func (Parser) AllowNetwork ¶
AllowNetwork controls whether the parser is allowed to fetch resources over the network (e.g. external DTDs, entities). When set to false, all network access is forbidden. libxml2: XML_PARSE_NONET (note: semantics are inverted — libxml2 sets this flag to *forbid* network access, whereas AllowNetwork(true) *permits* it) Default: true (network access is allowed)
func (Parser) BaseURI ¶
BaseURI sets the document's base URI, used for resolving relative references such as external DTD system identifiers.
func (Parser) BigLineNumbers ¶
BigLineNumbers controls whether large line numbers are stored in the text PSVI field, allowing line numbers above 65535. libxml2: XML_PARSE_BIG_LINES Default: false
func (Parser) BlockXXE ¶
BlockXXE controls whether loading of external entities and DTDs is blocked, preventing XML External Entity (XXE) attacks. libxml2: XML_PARSE_NOXXE Default: false
func (Parser) Catalog ¶
func (p Parser) Catalog(c CatalogResolver) Parser
Catalog sets an XML Catalog for resolving external entity identifiers (public/system IDs) during parsing. When set, the parser consults the catalog before attempting to load external DTDs and entities.
func (Parser) CharBufferSize ¶
CharBufferSize sets the maximum number of bytes delivered in a single Characters or IgnorableWhitespace SAX callback. When size <= 0 (the default), all character data is delivered in one call. When size > 0, data longer than size bytes is split into chunks of at most size bytes, always respecting UTF-8 character boundaries.
func (Parser) CleanNamespaces ¶
CleanNamespaces controls whether redundant namespace declarations are removed from the resulting DOM tree. libxml2: XML_PARSE_NSCLEAN Default: false
func (Parser) CompactTextNodes ¶
CompactTextNodes controls whether the parser compacts small text nodes to reduce memory usage. libxml2: XML_PARSE_COMPACT Default: false
func (Parser) DefaultDTDAttributes ¶
DefaultDTDAttributes controls whether the parser adds default attributes defined in the DTD. When set to true, also enables LoadExternalDTD. libxml2: XML_PARSE_DTDATTR Default: false
func (Parser) ErrorHandler ¶
func (p Parser) ErrorHandler(h ErrorHandler) Parser
ErrorHandler sets the handler for validation errors produced during DTD validation ([ValidateDTD]). When set, individual errors are delivered to the handler as they occur. The returned error from Parse is ErrDTDValidationFailed on failure.
func (Parser) FS ¶ added in v0.0.2
FS sets the fs.FS used to load external resources referenced by the document — external DTDs ([LoadExternalDTD]) and external entities resolved through TreeBuilder.ResolveEntity. A nil value restores the default, which opens any path supplied to the parser via os.Open.
Note: the names handed to the FS are built with filepath.Join against the document's base URI, so they may be absolute and may use OS-specific separators on Windows. FS implementations that enforce fs.ValidPath (notably os.DirFS and testing/fstest.MapFS) will reject those names. Sandboxing the loader behind such an FS requires path normalization that is not yet performed by this package; for now, supply an FS implementation that accepts OS-style names.
func (Parser) FixBaseURIs ¶
FixBaseURIs controls whether xml:base URIs are fixed up during XInclude processing. When set to false, xml:base attributes are not adjusted on included content. libxml2: XML_PARSE_NOBASEFIX (note: semantics are inverted — libxml2 sets this flag to *disable* fixup, whereas FixBaseURIs(false) disables it) Default: true (xml:base URIs are fixed up)
func (Parser) IgnoreEncoding ¶
IgnoreEncoding controls whether the parser ignores the encoding declaration inside the document and uses the transport-level encoding instead. libxml2: XML_PARSE_IGNORE_ENC Default: false
func (Parser) LenientXMLDecl ¶
LenientXMLDecl relaxes XML declaration parsing so that the version, encoding, and standalone pseudo-attributes may appear in any order. Per the XML spec (section 2.8) the order MUST be version, encoding, standalone, but some real-world producers emit them differently. This is a helium extension not present in libxml2. Default: false
func (Parser) LoadExternalDTD ¶
LoadExternalDTD controls whether the parser loads the external DTD subset. libxml2: XML_PARSE_DTDLOAD Default: false
func (Parser) MaxDepth ¶
MaxDepth sets the maximum element nesting depth allowed during parsing. When depth is greater than zero, the parser returns an error if the input document contains elements nested deeper than this limit. A value of zero (the default) means no limit is enforced.
func (Parser) MaxExternalDTDBytes ¶ added in v0.2.0
MaxExternalDTDBytes sets the maximum number of bytes read from an external DTD subset (see [LoadExternalDTD], [ValidateDTD], [DefaultDTDAttributes]). The cap is enforced against the actual number of bytes read, guarding against hostile or pathological sources (e.g. /dev/zero) that could otherwise exhaust memory before any entity or parse limits apply. A value less than or equal to zero (the default) means MaxExternalDTDSize (10 MiB) is used.
func (Parser) MergeCDATA ¶
MergeCDATA controls whether CDATA sections are merged into adjacent text nodes instead of being represented as separate CDATA nodes. libxml2: XML_PARSE_NOCDATA Default: false
func (Parser) NewPushParser ¶
func (p Parser) NewPushParser(ctx context.Context) *PushParser
NewPushParser creates a PushParser using the given Parser's configuration. The parser runs in a background goroutine, reading from the internal stream as data is pushed.
func (Parser) Parse ¶
Parse parses XML from a byte slice and returns the resulting Document (libxml2: xmlParseDoc / xmlParseMemory).
When [ValidateDTD] is enabled and the document fails validation, the returned error is ErrDTDValidationFailed and the document is still returned. Individual validation errors are delivered to the ErrorHandler configured via Parser.ErrorHandler.
Cancellation: if ctx is cancelled or its deadline is exceeded, Parse aborts and returns the context error (matched by errors.Is against context.Canceled / context.DeadlineExceeded) with a nil Document — never a partial tree. Because Parse reads from an in-memory byte slice there is no blocking read, so cancellation is always observed promptly: the parser checks the context between parse steps and between cursor refills.
func (Parser) ParseFile ¶
ParseFile reads and parses an XML file. The document's URL is set to the absolute path of the file, and the file path is used as the base URI for relative URI resolution during parsing.
func (Parser) ParseInNodeContext ¶
ParseInNodeContext parses an XML fragment in the context of an existing node. The node provides in-scope namespace declarations and document-level DTD/entity context. Returns the first node of the parsed fragment list (siblings linked via NextSibling). The returned nodes are not attached to any parent.
func (Parser) ParseReader ¶
ParseReader parses XML from an io.Reader and returns the resulting Document (libxml2: xmlReadIO). This is identical to [Parse] but reads from a stream instead of a byte slice. See [Parse] for DTD validation error handling.
EBCDIC encoding detection requires the full input up front: when the leading bytes carry the EBCDIC invariant prefix the reader is buffered into memory and parsed through the same path as [Parse], so an EBCDIC document parses identically via ParseReader/ParseFile as via Parse. All other inputs stream.
Cancellation: context cancellation and deadlines are observed BETWEEN read operations and parse steps. The parser checks ctx before each cursor refill (read from r) and between parse steps, so a cancelled or timed-out context is honored as soon as the parser regains control, returning the context error (matched by errors.Is against context.Canceled / context.DeadlineExceeded) with a nil Document.
A reader already blocked inside its own Read call cannot be interrupted generically: Go provides no way to unblock a Read in progress. Such a read is only interruptible if r itself honors the context or a deadline — for example a reader that sets a read deadline when ctx.Done() fires, or that returns from Read with an error on cancellation. If r can block indefinitely (e.g. a slow or never-returning network reader), wrap it so its Read observes ctx, or pass the already-read bytes to [Parse] instead.
func (Parser) PedanticErrors ¶
PedanticErrors controls whether the parser reports pedantic warnings for minor specification violations. libxml2: XML_PARSE_PEDANTIC Default: false
func (Parser) ProcessXInclude ¶
ProcessXInclude controls whether XInclude substitution is performed during parsing. libxml2: XML_PARSE_XINCLUDE Default: false
func (Parser) RecoverOnError ¶
RecoverOnError controls whether the parser attempts to recover from well-formedness errors and returns a partial document. libxml2: XML_PARSE_RECOVER Default: false
func (Parser) RelaxLimits ¶
RelaxLimits controls whether hardcoded parser limits (name length, entity expansion) are relaxed. Use with caution — disabling limits may expose the parser to denial-of-service attacks. libxml2: XML_PARSE_HUGE Default: false
func (Parser) ReuseDict ¶
ReuseDict controls whether the parser reuses the context dictionary for interned strings. When set to false, a fresh dictionary is used. libxml2: XML_PARSE_NODICT (note: semantics are inverted — libxml2 sets this flag to *disable* dictionary reuse, whereas ReuseDict(false) disables it) Default: true (dictionary is reused)
func (Parser) SAXHandler ¶
func (p Parser) SAXHandler(s sax.SAX2Handler) Parser
SAXHandler sets the SAX2 event handler for parsing.
func (Parser) SkipIDs ¶
SkipIDs controls whether ID attribute interning is skipped during parsing. When true, the parser does not build the ID table. libxml2: XML_PARSE_SKIP_IDS Default: false
func (Parser) StripBlanks ¶
StripBlanks controls whether whitespace-only text nodes are removed from the resulting DOM tree. libxml2: XML_PARSE_NOBLANKS Default: false
func (Parser) SubstituteEntities ¶
SubstituteEntities controls whether entity references are replaced with their substitution text during parsing. libxml2: XML_PARSE_NOENT Default: false
func (Parser) SuppressErrors ¶
SuppressErrors controls whether error reports from the parser are suppressed. When true, the SAX error callback is not invoked. libxml2: XML_PARSE_NOERROR Default: false
func (Parser) SuppressWarnings ¶
SuppressWarnings controls whether warning reports from the parser are suppressed. When true, the SAX warning callback is not invoked. libxml2: XML_PARSE_NOWARNING Default: false
func (Parser) ValidateDTD ¶
ValidateDTD controls whether the parser validates the document against its DTD after parsing. When set to true, also enables LoadExternalDTD. libxml2: XML_PARSE_DTDVALID Default: false
func (Parser) XIncludeNodes ¶
XIncludeNodes controls whether XINCLUDE START/END marker nodes are generated in the DOM tree during XInclude processing. libxml2: XML_PARSE_NOXINCNODE (note: semantics are inverted — libxml2 sets this flag to *suppress* marker nodes, whereas XIncludeNodes(false) suppresses them) Default: true (marker nodes are generated)
type ProcessingInstruction ¶
type ProcessingInstruction struct {
// contains filtered or unexported fields
}
ProcessingInstruction represents an XML processing instruction node (libxml2: xmlNode with type XML_PI_NODE).
func (*ProcessingInstruction) AddChild ¶
func (p *ProcessingInstruction) AddChild(cur Node) error
AddChild on a PI does not attach child nodes. A processing instruction carries its content as a string (the "data" portion), not as element/text children. This mirrors libxml2, where an xmlNode of type XML_PI_NODE stores its content in the node's content string and has no element/text children.
A Text/CDATA child has its content appended to the PI data (mirroring xmlNodeAddContent on a PI). Any other node type is rejected, since attaching it would corrupt the tree and break serialization.
func (*ProcessingInstruction) AddSibling ¶
func (p *ProcessingInstruction) AddSibling(cur Node) error
func (*ProcessingInstruction) AppendText ¶
func (p *ProcessingInstruction) AppendText(b []byte) error
AppendText appends text to the PI's data string rather than creating a child text node. See AddChild for rationale.
func (*ProcessingInstruction) Content ¶
func (p *ProcessingInstruction) Content() []byte
func (ProcessingInstruction) FirstChild ¶
func (n ProcessingInstruction) FirstChild() Node
func (*ProcessingInstruction) Name ¶
func (p *ProcessingInstruction) Name() string
func (ProcessingInstruction) NextSibling ¶
func (n ProcessingInstruction) NextSibling() Node
func (ProcessingInstruction) OwnerDocument ¶
func (n ProcessingInstruction) OwnerDocument() *Document
func (ProcessingInstruction) PrevSibling ¶
func (n ProcessingInstruction) PrevSibling() Node
func (*ProcessingInstruction) Replace ¶
func (p *ProcessingInstruction) Replace(nodes ...Node) error
func (*ProcessingInstruction) SetNextSibling ¶
func (n *ProcessingInstruction) SetNextSibling(cur Node)
func (*ProcessingInstruction) SetOwnerDocument ¶
func (n *ProcessingInstruction) SetOwnerDocument(doc *Document)
func (*ProcessingInstruction) SetPrevSibling ¶
func (n *ProcessingInstruction) SetPrevSibling(cur Node)
func (*ProcessingInstruction) SetTreeDoc ¶
func (p *ProcessingInstruction) SetTreeDoc(doc *Document)
func (*ProcessingInstruction) Type ¶
func (p *ProcessingInstruction) Type() ElementType
type PushParser ¶
PushParser provides an incremental XML parsing interface (libxml2: xmlParserCtxt in push mode). Data is pushed via Push or Write, and the parser processes tokens as they become available in a background goroutine. Call [PushParser.Close] to signal end-of-input and retrieve the parsed Document.
type QNamePredicate ¶
type QNamePredicate string
QNamePredicate matches an attribute by QName as returned by Attribute.Name.
func (QNamePredicate) Match ¶
func (p QNamePredicate) Match(a *Attribute) bool
type SubstitutionType ¶
type SubstitutionType int
const ( SubstituteNone SubstitutionType = iota SubstituteRef SubstitutePERef SubstituteBoth )
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text represents an XML text node (libxml2: xmlNode with type XML_TEXT_NODE).
func (*Text) AddNamespaceDecl ¶ added in v0.3.0
func (n *Text) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*Text) AddSibling ¶
func (*Text) AppendText ¶
func (Text) Content ¶
Content returns a defensive copy of the text node's content. Mutating the returned slice does NOT affect the node; re-reading returns the original bytes.
func (*Text) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (Text) Namespaces ¶
func (n Text) Namespaces() []*Namespace
func (*Text) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*Text) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*Text) SetNs ¶
func (n *Text) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*Text) SetTreeDoc ¶
type TreeBuilder ¶
type TreeBuilder struct{}
TreeBuilder is a SAX2 handler that builds a DOM tree from SAX events, analogous to libxml2's default SAX handler (xmlSAX2InitDefaultSAXHandler).
func NewTreeBuilder ¶
func NewTreeBuilder() *TreeBuilder
NewTreeBuilder creates a new TreeBuilder that builds a DOM tree from SAX events.
func (*TreeBuilder) AttributeDecl ¶
func (t *TreeBuilder) AttributeDecl(ctxif context.Context, eName string, aName string, typ enum.AttributeType, deftype enum.AttributeDefault, value string, enumif sax.Enumeration) error
func (*TreeBuilder) CDataBlock ¶
func (t *TreeBuilder) CDataBlock(ctxif context.Context, data []byte) error
CDataBlock mirrors xmlSAX2Text(ctxt, value, len, XML_CDATA_SECTION_NODE) in libxml2's SAX2.c. Unlike text nodes, adjacent CDATA sections are NOT merged — each callback creates a new CDATASection node.
func (*TreeBuilder) Characters ¶
func (t *TreeBuilder) Characters(ctxif context.Context, data []byte) error
func (*TreeBuilder) Comment ¶
func (t *TreeBuilder) Comment(ctxif context.Context, data []byte) error
Comment mirrors xmlSAX2Comment in libxml2's SAX2.c, which delegates parent selection to xmlSAX2AppendChild. When inside a DTD subset the comment is added to the DTD, not the document.
func (*TreeBuilder) ElementDecl ¶
func (t *TreeBuilder) ElementDecl(ctxif context.Context, name string, typ enum.ElementType, content sax.ElementContent) error
func (*TreeBuilder) EndDocument ¶
func (t *TreeBuilder) EndDocument(ctxif context.Context) error
func (*TreeBuilder) EndElementNS ¶
func (t *TreeBuilder) EndElementNS(ctxif context.Context, localname, prefix, uri string) error
func (*TreeBuilder) EndEntity ¶
func (t *TreeBuilder) EndEntity(ctxif context.Context, name string) error
func (*TreeBuilder) EntityDecl ¶
func (t *TreeBuilder) EntityDecl(ctxif context.Context, name string, typ enum.EntityType, publicID string, systemID string, notation string) error
func (*TreeBuilder) ExternalEntityDecl ¶
func (*TreeBuilder) ExternalSubset ¶
func (t *TreeBuilder) ExternalSubset(ctxif context.Context, name, eid, uri string) error
func (*TreeBuilder) GetExternalSubset ¶
func (*TreeBuilder) GetParameterEntity ¶
func (*TreeBuilder) HasExternalSubset ¶
func (t *TreeBuilder) HasExternalSubset(ctxif context.Context) (bool, error)
func (*TreeBuilder) HasInternalSubset ¶
func (t *TreeBuilder) HasInternalSubset(ctxif context.Context) (bool, error)
func (*TreeBuilder) IgnorableWhitespace ¶
func (t *TreeBuilder) IgnorableWhitespace(ctxif context.Context, content []byte) error
func (*TreeBuilder) InternalEntityDecl ¶
func (*TreeBuilder) InternalSubset ¶
func (t *TreeBuilder) InternalSubset(ctxif context.Context, name, eid, uri string) error
func (*TreeBuilder) IsStandalone ¶
func (t *TreeBuilder) IsStandalone(ctxif context.Context) (bool, error)
func (*TreeBuilder) NotationDecl ¶
func (*TreeBuilder) ProcessingInstruction ¶
func (t *TreeBuilder) ProcessingInstruction(ctxif context.Context, target, data string) error
func (*TreeBuilder) Reference ¶
func (t *TreeBuilder) Reference(ctxif context.Context, name string) error
func (*TreeBuilder) ResolveEntity ¶
func (t *TreeBuilder) ResolveEntity(ctxif context.Context, publicID string, systemID string) (sax.ParseInput, error)
func (*TreeBuilder) SetDocumentLocator ¶
func (t *TreeBuilder) SetDocumentLocator(ctxif context.Context, loc sax.DocumentLocator) error
func (*TreeBuilder) SkippedEntity ¶
func (t *TreeBuilder) SkippedEntity(ctxif context.Context, name string) error
func (*TreeBuilder) StartDocument ¶
func (t *TreeBuilder) StartDocument(ctxif context.Context) error
func (*TreeBuilder) StartElementNS ¶
func (*TreeBuilder) StartEntity ¶
func (t *TreeBuilder) StartEntity(ctxif context.Context, name string) error
func (*TreeBuilder) UnparsedEntityDecl ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer serializes an XML document tree (libxml2: xmlSaveCtxt).
It is a value-style wrapper: fluent methods return updated copies and the original is never mutated. Mutable runtime state (indent depth, resolved escapeNonASCII flag, XHTML detection) lives in a writeSession created inside each terminal method.
func (Writer) AllowPrefixUndeclarations ¶
AllowPrefixUndeclarations controls whether xmlns:prefix="" undeclarations may be emitted.
func (Writer) EscapeNonASCII ¶
EscapeNonASCII controls whether non-ASCII characters are escaped as numeric character references when serializing UTF-8 output.
func (Writer) IncludeDTD ¶
IncludeDTD controls whether DTD nodes are emitted.
func (Writer) IndentString ¶
IndentString sets the string used for each indent level.
func (Writer) SelfCloseEmptyElements ¶
SelfCloseEmptyElements controls whether empty elements are serialized as self-closing tags (for example, <br/>). When false, they are emitted as explicit open+close pairs (for example, <br></br>).
func (Writer) WriteTo ¶
WriteTo serializes a node (document or element) to the given writer. When the node is a Document, document-level setup (encoding, XHTML detection, DTD filtering) is applied automatically.
func (Writer) XMLDeclaration ¶
XMLDeclaration controls whether the XML declaration is emitted.
type XIncludeMarker ¶
type XIncludeMarker struct {
// contains filtered or unexported fields
}
XIncludeMarker is a marker node used to bracket XInclude-included content.
func NewXIncludeMarker ¶
func NewXIncludeMarker(doc *Document, etype ElementType, name string) *XIncludeMarker
NewXIncludeMarker creates an XInclude marker node (start or end).
func (*XIncludeMarker) AddChild ¶
func (n *XIncludeMarker) AddChild(cur Node) error
func (*XIncludeMarker) AddNamespaceDecl ¶ added in v0.3.0
func (n *XIncludeMarker) AddNamespaceDecl(ns *Namespace)
AddNamespaceDecl appends an existing Namespace to this node's declarations (nsDefs) without allocating a new one. Unlike DeclareNamespace it does not create a fresh Namespace, so a caller building a tree can reuse one Namespace object as both the declaration and an element's active namespace. The caller owns ns; it must not be shared as a declaration across nodes that could be mutated independently.
func (*XIncludeMarker) AddSibling ¶
func (n *XIncludeMarker) AddSibling(cur Node) error
func (*XIncludeMarker) AppendText ¶
func (n *XIncludeMarker) AppendText(b []byte) error
func (*XIncludeMarker) DeclareNamespace ¶
DeclareNamespace declares a namespace on this node without making it the node's active namespace (libxml2: xmlNewNs).
func (XIncludeMarker) Namespaces ¶
func (n XIncludeMarker) Namespaces() []*Namespace
func (*XIncludeMarker) RemoveNamespaceByPrefix ¶
RemoveNamespaceByPrefix removes a namespace declaration with the given prefix. Returns true if a declaration was removed.
func (*XIncludeMarker) Replace ¶
func (n *XIncludeMarker) Replace(nodes ...Node) error
func (*XIncludeMarker) SetActiveNamespace ¶
SetActiveNamespace declares a namespace and sets it as this node's active namespace (libxml2: xmlSetNs).
func (*XIncludeMarker) SetNs ¶
func (n *XIncludeMarker) SetNs(ns *Namespace)
SetNs sets the node's active namespace to an existing Namespace object without creating a new declaration.
func (*XIncludeMarker) SetTreeDoc ¶
func (n *XIncludeMarker) SetTreeDoc(doc *Document)
Source Files
¶
- attribute.go
- bitset.go
- copy.go
- copy_core.go
- doc.go
- document.go
- dtd.go
- dtd_attr.go
- dtd_elem.go
- element.go
- entity.go
- errorhandler.go
- errors.go
- intern.go
- iter.go
- node.go
- node_base.go
- node_leaf.go
- node_namespace.go
- parser.go
- parser_content.go
- parser_decl.go
- parser_document.go
- parser_dtd_attr.go
- parser_dtd_element.go
- parser_dtd_subset.go
- parser_element.go
- parser_encoding.go
- parser_entity_decl.go
- parser_entity_ref.go
- parser_state_gen.go
- parser_whitespace.go
- parser_xml_decl.go
- parserctx.go
- resolver.go
- stack.go
- tree_builder.go
- tree_fastpath.go
- tree_namespaces.go
- valid.go
- writer.go
- writer_dtd.go
- writer_escape.go
- writer_xhtml.go
- xinclude.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bench contains parse benchmarks for helium vs libxml2.
|
Package bench contains parse benchmarks for helium vs libxml2. |
|
Package c14n implements XML canonicalization (C14N) as defined by the W3C specifications: Canonical XML 1.0, Exclusive Canonical XML 1.0, and Canonical XML 1.1.
|
Package c14n implements XML canonicalization (C14N) as defined by the W3C specifications: Canonical XML 1.0, Exclusive Canonical XML 1.0, and Canonical XML 1.1. |
|
Package catalog implements OASIS XML Catalog resolution for public/system identifiers and URIs.
|
Package catalog implements OASIS XML Catalog resolution for public/system identifiers and URIs. |
|
cmd
|
|
|
helium
command
|
|
|
Package enum centralizes shared enumeration symbols used across packages.
|
Package enum centralizes shared enumeration symbols used across packages. |
|
Package html implements an HTML parser compatible with libxml2's HTMLparser.
|
Package html implements an HTML parser compatible with libxml2's HTMLparser. |
|
internal
|
|
|
catalog
Package catalog implements OASIS XML Catalog resolution for public/system identifiers and URIs.
|
Package catalog implements OASIS XML Catalog resolution for public/system identifiers and URIs. |
|
domutil
Package domutil hosts small DOM/QName helpers shared by several helium processing packages (c14n, xmldsig1, xmlenc1, xpath1, xpath3, xslt3).
|
Package domutil hosts small DOM/QName helpers shared by several helium processing packages (c14n, xmldsig1, xmlenc1, xpath1, xpath3, xslt3). |
|
encoding
Package encoding wraps around the various encoding stuff in golang.org/x/text/encoding.
|
Package encoding wraps around the various encoding stuff in golang.org/x/text/encoding. |
|
heliumtest
Package heliumtest provides test helpers shared across helium packages.
|
Package heliumtest provides test helpers shared across helium packages. |
|
iofs
Package iofs provides the default fs.FS used by helium for opening external resources (DTDs, entities, schemas, XInclude targets).
|
Package iofs provides the default fs.FS used by helium for opening external resources (DTDs, entities, schemas, XInclude targets). |
|
iolimit
Package iolimit provides a bounded read-all helper shared by the parser, xinclude, and xslt3 resource loaders.
|
Package iolimit provides a bounded read-all helper shared by the parser, xinclude, and xslt3 resource loaders. |
|
lexicon
Package lexicon defines shared spec vocabulary reused across helium packages.
|
Package lexicon defines shared spec vocabulary reused across helium packages. |
|
sequence
Package sequence provides generic sequence types for ordered collections with lazy evaluation support.
|
Package sequence provides generic sequence types for ordered collections with lazy evaluation support. |
|
strcursor
Package strcursor provides buffered cursor types for reading runes and bytes from an io.Reader.
|
Package strcursor provides buffered cursor types for reading runes and bytes from an io.Reader. |
|
unparsedtext
Package unparsedtext implements the text resource loading pipeline for XPath 3.1 fn:unparsed-text, fn:unparsed-text-available, fn:unparsed-text-lines, and the document retrieval that backs fn:doc / fn:json-doc.
|
Package unparsedtext implements the text resource loading pipeline for XPath 3.1 fn:unparsed-text, fn:unparsed-text-available, fn:unparsed-text-lines, and the document retrieval that backs fn:doc / fn:json-doc. |
|
xmlbase64
Package xmlbase64 decodes xs:base64Binary lexical values that may contain interspersed XML whitespace (space, tab, CR, LF).
|
Package xmlbase64 decodes xs:base64Binary lexical values that may contain interspersed XML whitespace (space, tab, CR, LF). |
|
xmlchar
Package xmlchar provides XML 1.0 NCName character classification functions.
|
Package xmlchar provides XML 1.0 NCName character classification functions. |
|
xpathstream
Package xpathstream provides streamability analysis helpers for XPath 3.1 expressions.
|
Package xpathstream provides streamability analysis helpers for XPath 3.1 expressions. |
|
Package push provides a generic push parser that accepts data in chunks and parses it in a background goroutine.
|
Package push provides a generic push parser that accepts data in chunks and parses it in a background goroutine. |
|
Package relaxng implements RELAX NG (XML syntax) schema compilation and validation.
|
Package relaxng implements RELAX NG (XML syntax) schema compilation and validation. |
|
Package sax defines the SAX2 event-driven XML parsing interface.
|
Package sax defines the SAX2 event-driven XML parsing interface. |
|
Package schematron implements Schematron schema compilation and validation.
|
Package schematron implements Schematron schema compilation and validation. |
|
Package shim provides a drop-in replacement for encoding/xml backed by the helium XML parser.
|
Package shim provides a drop-in replacement for encoding/xml backed by the helium XML parser. |
|
Package sink provides a generic, channel-based asynchronous event sink.
|
Package sink provides a generic, channel-based asynchronous event sink. |
|
Package stream implements a streaming XML writer that produces well-formed XML incrementally via method calls, writing directly to an io.Writer without building an in-memory DOM tree.
|
Package stream implements a streaming XML writer that produces well-formed XML incrementally via method calls, writing directly to an io.Writer without building an in-memory DOM tree. |
|
tools
|
|
|
internal/gen
Package gen holds helpers shared by the helium code generators (tools/qt3gen and tools/xslt3gen).
|
Package gen holds helpers shared by the helium code generators (tools/qt3gen and tools/xslt3gen). |
|
qt3gen
command
Command qt3gen parses the W3C QT3 (XPath/XQuery Test Suite 3) catalog and generates a table-driven Go test file for the xpath3 package.
|
Command qt3gen parses the W3C QT3 (XPath/XQuery Test Suite 3) catalog and generates a table-driven Go test file for the xpath3 package. |
|
xslt3gen
command
Command xslt3gen parses the W3C XSLT 3.0 test catalog and generates table-driven Go test files for the xslt3 package.
|
Command xslt3gen parses the W3C XSLT 3.0 test catalog and generates table-driven Go test files for the xslt3 package. |
|
Package xinclude implements XML Inclusion (XInclude) 1.0 processing.
|
Package xinclude implements XML Inclusion (XInclude) 1.0 processing. |
|
Package xmldsig1 implements W3C XML Digital Signatures 1.1.
|
Package xmldsig1 implements W3C XML Digital Signatures 1.1. |
|
Package xmlenc1 implements W3C XML Encryption 1.1.
|
Package xmlenc1 implements W3C XML Encryption 1.1. |
|
Package xpath1 implements XPath 1.0 expression parsing and evaluation against helium XML document trees.
|
Package xpath1 implements XPath 1.0 expression parsing and evaluation against helium XML document trees. |
|
Package xpath3 implements XPath 3.1 expression parsing and evaluation against helium XML document trees.
|
Package xpath3 implements XPath 3.1 expression parsing and evaluation against helium XML document trees. |
|
Package xpointer implements XPointer framework and element() scheme resolution (libxml2: xpointer module / xmlXPtrEval).
|
Package xpointer implements XPointer framework and element() scheme resolution (libxml2: xpointer module / xmlXPtrEval). |
|
Package xsd implements XML Schema (XSD) 1.0 compilation and validation.
|
Package xsd implements XML Schema (XSD) 1.0 compilation and validation. |
|
Package xslt3 implements an XSLT 3.0 processor targeting Basic XSLT 3.0 conformance (W3C spec Section 27).
|
Package xslt3 implements an XSLT 3.0 processor targeting Basic XSLT 3.0 conformance (W3C spec Section 27). |