Documentation ¶
Index ¶
- Constants
- Variables
- func SetupXPathCallback()
- func WrapNode(n uintptr) (types.Node, error)
- type Attribute
- type C14NMode
- type C14NSerialize
- type CDataSection
- type Comment
- type Document
- func (d *Document) AddChild(n types.Node) error
- func (d *Document) AutoFree()
- func (d *Document) ChildNodes() (types.NodeList, error)
- func (d *Document) Copy() (types.Node, error)
- func (d *Document) CreateAttribute(k, v string) (*Attribute, error)
- func (d *Document) CreateAttributeNS(nsuri, k, v string) (*Attribute, error)
- func (d *Document) CreateCDataSection(txt string) (*CDataSection, error)
- func (d *Document) CreateCommentNode(txt string) (*Comment, error)
- func (d *Document) CreateElement(name string) (types.Element, error)
- func (d *Document) CreateElementNS(nsuri, name string) (types.Element, error)
- func (d *Document) CreateTextNode(txt string) (*Text, error)
- func (d *Document) DocumentElement() (types.Node, error)
- func (d *Document) Dump(format bool) string
- func (d *Document) Encoding() string
- func (d *Document) Find(xpath string) (types.XPathResult, error)
- func (d *Document) FirstChild() (types.Node, error)
- func (d *Document) Free()
- func (d *Document) HasChildNodes() bool
- func (d *Document) IsSameNode(n types.Node) bool
- func (d *Document) LastChild() (types.Node, error)
- func (d *Document) Literal() (string, error)
- func (d *Document) LookupNamespacePrefix(href string) (string, error)
- func (d *Document) LookupNamespaceURI(prefix string) (string, error)
- func (d *Document) MakeMortal()
- func (d *Document) MakePersistent()
- func (d *Document) NextSibling() (types.Node, error)
- func (d *Document) NodeName() string
- func (d *Document) NodeType() clib.XMLNodeType
- func (d *Document) NodeValue() string
- func (d *Document) OwnerDocument() (types.Document, error)
- func (d *Document) ParentNode() (types.Node, error)
- func (d *Document) ParseInContext(s string, n int) (types.Node, error)
- func (d *Document) Pointer() uintptr
- func (d *Document) PreviousSibling() (types.Node, error)
- func (d *Document) RemoveChild(n types.Node) error
- func (d *Document) SetBaseURI(s string)
- func (d *Document) SetDocument(n types.Document) error
- func (d *Document) SetDocumentElement(n types.Node) error
- func (d *Document) SetEncoding(e string)
- func (d *Document) SetNodeName(s string)
- func (d *Document) SetNodeValue(s string)
- func (d *Document) SetStandalone(v int)
- func (d *Document) SetVersion(v string)
- func (d *Document) Standalone() int
- func (d *Document) String() string
- func (d *Document) TextContent() string
- func (d *Document) ToString(x int, b bool) string
- func (d *Document) URI() string
- func (d *Document) Version() string
- func (d *Document) Walk(fn func(types.Node) error) error
- type Element
- func (n *Element) AppendText(s string) error
- func (n *Element) Attributes() ([]types.Attribute, error)
- func (n *Element) GetAttribute(name string) (types.Attribute, error)
- func (n *Element) GetNamespaces() ([]types.Namespace, error)
- func (n Element) Literal() (string, error)
- func (n *Element) RemoveAttribute(name string) error
- func (n *Element) SetAttribute(name, value string) error
- func (n *Element) SetNamespace(uri, prefix string, activate ...bool) error
- type Namespace
- type Pi
- type Serializer
- type Text
- type XMLNode
- func (n *XMLNode) AddChild(child types.Node) error
- func (n *XMLNode) AutoFree()
- func (n *XMLNode) ChildNodes() (types.NodeList, error)
- func (n *XMLNode) Copy() (types.Node, error)
- func (n *XMLNode) Find(expr string) (types.XPathResult, error)
- func (n *XMLNode) FindExpr(expr *xpath.Expression) (types.XPathResult, error)
- func (n *XMLNode) FirstChild() (types.Node, error)
- func (n *XMLNode) Free()
- func (n *XMLNode) HasChildNodes() bool
- func (n *XMLNode) IsSameNode(other types.Node) bool
- func (n *XMLNode) LastChild() (types.Node, error)
- func (n XMLNode) Literal() (string, error)
- func (n *XMLNode) LocalName() string
- func (n *XMLNode) LookupNamespacePrefix(href string) (string, error)
- func (n *XMLNode) LookupNamespaceURI(prefix string) (string, error)
- func (n *XMLNode) MakeMortal()
- func (n *XMLNode) MakePersistent()
- func (n *XMLNode) NamespaceURI() string
- func (n *XMLNode) NextSibling() (types.Node, error)
- func (n *XMLNode) NodeName() string
- func (n *XMLNode) NodeType() clib.XMLNodeType
- func (n *XMLNode) NodeValue() string
- func (n *XMLNode) OwnerDocument() (types.Document, error)
- func (n *XMLNode) ParentNode() (types.Node, error)
- func (n *XMLNode) ParseInContext(s string, o int) (types.Node, error)
- func (n *XMLNode) Pointer() uintptr
- func (n *XMLNode) Prefix() string
- func (n *XMLNode) PreviousSibling() (types.Node, error)
- func (n *XMLNode) RemoveChild(t types.Node) error
- func (n *XMLNode) SetDocument(d types.Document) error
- func (n *XMLNode) SetNodeName(name string)
- func (n *XMLNode) SetNodeValue(value string)
- func (n *XMLNode) String() string
- func (n *XMLNode) TextContent() string
- func (n *XMLNode) ToString(format int, docencoding bool) string
- func (n *XMLNode) Walk(fn func(types.Node) error) error
- type XMLNodeType
Constants ¶
const ( ElementNode = clib.ElementNode AttributeNode = clib.AttributeNode TextNode = clib.TextNode CDataSectionNode = clib.CDataSectionNode EntityRefNode = clib.EntityRefNode EntityNode = clib.EntityNode PiNode = clib.PiNode CommentNode = clib.CommentNode DocumentNode = clib.DocumentNode DocumentTypeNode = clib.DocumentTypeNode DocumentFragNode = clib.DocumentFragNode NotationNode = clib.NotationNode HTMLDocumentNode = clib.HTMLDocumentNode DTDNode = clib.DTDNode ElementDecl = clib.ElementDecl AttributeDecl = clib.AttributeDecl EntityDecl = clib.EntityDecl NamespaceDecl = clib.NamespaceDecl XIncludeStart = clib.XIncludeStart XIncludeEnd = clib.XIncludeEnd DocbDocumentNode = clib.DocbDocumentNode )
Variables ¶
var ( ErrAttributeNotFound = clib.ErrAttributeNotFound ErrInvalidNodeType = errors.New("invalid node type") )
Functions ¶
func SetupXPathCallback ¶
func SetupXPathCallback()
Types ¶
type Attribute ¶
type Attribute struct {
XMLNode
}
func (*Attribute) HasChildNodes ¶
HasChildNodes returns true if the node contains any child nodes. By definition attributes cannot have children, so this always returns false
type C14NSerialize ¶
C14NSerialize implements the Serializer interface, and generates XML in C14N format.
type CDataSection ¶
type CDataSection struct {
XMLNode
}
func (*CDataSection) Literal ¶
func (n *CDataSection) Literal() (string, error)
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
func CreateDocument ¶
func CreateDocument() *Document
CreateDocument creates a new document with version="1.0", and no encoding
func NewDocument ¶
NewDocument creates a new document
func WrapDocument ¶
func (*Document) AutoFree ¶
func (d *Document) AutoFree()
AutoFree calls Free() if the document is moral.
func (*Document) ChildNodes ¶
ChildNodes returns the document element
func (*Document) CreateAttribute ¶
CreateAttribute creates a new attribute
func (*Document) CreateAttributeNS ¶
CreateAttributeNS creates a new attribute with the given XML namespace
func (*Document) CreateCDataSection ¶
func (d *Document) CreateCDataSection(txt string) (*CDataSection, error)
CreateCDataSection creates a new CDATA section node
func (*Document) CreateCommentNode ¶
CreateCommentNode creates a new comment node
func (*Document) CreateElement ¶
CreateElement creates a new element node
func (*Document) CreateElementNS ¶
CreateElementNS creates a new element node in the given XML namespace
func (*Document) CreateTextNode ¶
CreateTextNode creates a new text node
func (*Document) DocumentElement ¶
DocumentElement returns the root node of the document
func (*Document) Find ¶
func (d *Document) Find(xpath string) (types.XPathResult, error)
Find returns the nodes that can be selected with the given xpath string
func (*Document) FirstChild ¶
FirstChild returns the document element
func (*Document) HasChildNodes ¶
HasChildNodes returns true if the document node is available
func (*Document) IsSameNode ¶
IsSameNode checks if the underlying C pointer points to the same C struct
func (*Document) LookupNamespacePrefix ¶
LookupNamespacePrefix looks for a namespace prefix that matches the given namespace URI
func (*Document) LookupNamespaceURI ¶
LookupNamespaceURI looks for a namespace uri that matches the given namespace prefix
func (*Document) MakePersistent ¶
func (d *Document) MakePersistent()
MakePersistent unsets the flag
func (*Document) NextSibling ¶
NextSibling always returns nil for Document
func (*Document) NodeType ¶
func (d *Document) NodeType() clib.XMLNodeType
NodeType returns the XMLNodeType
func (*Document) OwnerDocument ¶
OwnerDocument always returns the document itself
func (*Document) ParentNode ¶
ParentNode always returns an error for a document
func (*Document) ParseInContext ¶
ParseInContext is currently unimplemented
func (*Document) PreviousSibling ¶
PreviousSibling always returns nil for Document
func (*Document) SetDocument ¶
SetDocument always returns an error for a document
func (*Document) SetDocumentElement ¶
SetDocumentElement sets the document element
func (*Document) SetEncoding ¶
SetEncoding sets the encoding of the document
func (*Document) SetNodeName ¶
SetNodeName is a no op for document
func (*Document) SetNodeValue ¶
SetNodeValue is a no op for document
func (*Document) SetStandalone ¶
SetStandalone sets the standalone flag
func (*Document) SetVersion ¶
SetVersion sets the version of the document
func (*Document) Standalone ¶
Standalone returns the value of the standalone flag
func (*Document) TextContent ¶
TextContent returns the text content
type Element ¶
type Element struct {
XMLNode
}
func (*Element) AppendText ¶
AppendText adds a new text node
func (*Element) Attributes ¶
Attributes returns a list of attributes on a node
func (*Element) GetAttribute ¶
GetAttribute retrieves the value of an attribute
func (*Element) GetNamespaces ¶
GetNamespaces returns Namespace objects associated with this element. WARNING: This method currently returns namespace objects which allocates C structures for each namespace. Therefore you MUST free the structures, or otherwise you WILL leak memory.
func (Element) Literal ¶
Literal returns a stringified version of this node and its children, inclusive.
func (*Element) RemoveAttribute ¶
RemoveAttribute completely removes an attribute from the node
func (*Element) SetAttribute ¶
SetAttribute sets an attribute
func (*Element) SetNamespace ¶
SetNamespace sets up a new namespace on the given node. An XML namespace declaration is explicitly created only if the activate flag is enabled, and the namespace is not declared in a previous tree hierarchy.
type Namespace ¶
type Namespace struct {
XMLNode
}
type Serializer ¶
type XMLNode ¶
type XMLNode struct {
// contains filtered or unexported fields
}
func (*XMLNode) AutoFree ¶
func (n *XMLNode) AutoFree()
AutoFree allows you to free the underlying C resources. It is meant to be called from defer. If you don't call `MakeMortal()` or do call `MakePersistent()`, AutoFree is a no-op.
func (*XMLNode) ChildNodes ¶
ChildNodes returns the child nodes
func (*XMLNode) Find ¶
func (n *XMLNode) Find(expr string) (types.XPathResult, error)
Find evaluates the xpath expression and returns the matching nodes
func (*XMLNode) FindExpr ¶
func (n *XMLNode) FindExpr(expr *xpath.Expression) (types.XPathResult, error)
FindExpr evalues the pre-compiled xpath expression and returns the matching nodes
func (*XMLNode) FirstChild ¶
FirstChild reutrns the first child node
func (*XMLNode) HasChildNodes ¶
HasChildNodes returns true if the node contains children
func (*XMLNode) IsSameNode ¶
IsSameNode returns true if two nodes point to the same node
func (*XMLNode) LookupNamespacePrefix ¶
LookupNamespacePrefix returns the prefix associated with the given URL
func (*XMLNode) LookupNamespaceURI ¶
LookupNamespaceURI returns the URI associated with the given prefix
func (*XMLNode) MakeMortal ¶
func (n *XMLNode) MakeMortal()
MakeMortal flags the node so that `AutoFree` calls Free() to release the underlying C resources.
func (*XMLNode) MakePersistent ¶
func (n *XMLNode) MakePersistent()
MakePersistent flags the node so that `AutoFree` becomes a no-op. Make sure to call this if you used `MakeMortal` and `AutoFree`, but you then decided to keep the node around.
func (*XMLNode) NamespaceURI ¶
NamespaceURI returns the namespace URI associated with this node
func (*XMLNode) NextSibling ¶
NextSibling returns the next sibling
func (*XMLNode) NodeType ¶
func (n *XMLNode) NodeType() clib.XMLNodeType
NodeType returns the XMLNodeType
func (*XMLNode) OwnerDocument ¶
OwnerDocument returns the Document that this node belongs to
func (*XMLNode) ParentNode ¶
ParentNode returns the parent node
func (*XMLNode) ParseInContext ¶
ParseInContext parses a chunk of XML in the context of the current node. This makes it safe to append the resulting node to the current node or other nodes in the same document.
func (*XMLNode) PreviousSibling ¶
PreviousSibling returns the previous sibling
func (*XMLNode) SetDocument ¶
SetDocument sets the document of this node and its descendants
func (*XMLNode) SetNodeName ¶
SetNodeName sets the node name
func (*XMLNode) SetNodeValue ¶
SetNodeValue sets the node value
func (*XMLNode) TextContent ¶
TextContent returns the text content
type XMLNodeType ¶
type XMLNodeType clib.XMLNodeType
XMLNodeType identifies the type of the underlying C struct