dom

package
v0.0.0-...-e6d9de6 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
var (
	ErrAttributeNotFound = clib.ErrAttributeNotFound
	ErrInvalidNodeType   = errors.New("invalid node type")
)

Functions

func SetupXPathCallback

func SetupXPathCallback()

func WrapNode

func WrapNode(n uintptr) (types.Node, error)

WrapNode is a function created with the sole purpose of allowing go-libxml2 consumers that can generate a C.xmlNode pointer to create libxml2.Node types, e.g. go-xmlsec.

Types

type Attribute

type Attribute struct {
	XMLNode
}

func (*Attribute) Free

func (n *Attribute) Free()

Free releases the underlying C struct

func (*Attribute) HasChildNodes

func (n *Attribute) HasChildNodes() bool

HasChildNodes returns true if the node contains any child nodes. By definition attributes cannot have children, so this always returns false

func (*Attribute) Value

func (n *Attribute) Value() string

Value returns the value of the attribute.

type C14NMode

type C14NMode int

C14NMode represents the C14N mode supported by libxml2

const (
	C14N1_0 C14NMode = iota
	C14NExclusive1_0
	C14N1_1
)

type C14NSerialize

type C14NSerialize struct {
	Mode         C14NMode
	WithComments bool
}

C14NSerialize implements the Serializer interface, and generates XML in C14N format.

func (C14NSerialize) Serialize

func (s C14NSerialize) Serialize(n types.Node) (string, error)

Serialize produces serialization of the document, canonicalized.

type CDataSection

type CDataSection struct {
	XMLNode
}

func (*CDataSection) Literal

func (n *CDataSection) Literal() (string, error)

type Comment

type Comment struct {
	XMLNode
}

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

func NewDocument(version, encoding string) *Document

NewDocument creates a new document

func WrapDocument

func WrapDocument(n uintptr) *Document

func (*Document) AddChild

func (d *Document) AddChild(n types.Node) error

AddChild is a no op for Document

func (*Document) AutoFree

func (d *Document) AutoFree()

AutoFree calls Free() if the document is moral.

func (*Document) ChildNodes

func (d *Document) ChildNodes() (types.NodeList, error)

ChildNodes returns the document element

func (*Document) Copy

func (d *Document) Copy() (types.Node, error)

Copy is currently unimplemented

func (*Document) CreateAttribute

func (d *Document) CreateAttribute(k, v string) (*Attribute, error)

CreateAttribute creates a new attribute

func (*Document) CreateAttributeNS

func (d *Document) CreateAttributeNS(nsuri, k, v string) (*Attribute, error)

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

func (d *Document) CreateCommentNode(txt string) (*Comment, error)

CreateCommentNode creates a new comment node

func (*Document) CreateElement

func (d *Document) CreateElement(name string) (types.Element, error)

CreateElement creates a new element node

func (*Document) CreateElementNS

func (d *Document) CreateElementNS(nsuri, name string) (types.Element, error)

CreateElementNS creates a new element node in the given XML namespace

func (*Document) CreateTextNode

func (d *Document) CreateTextNode(txt string) (*Text, error)

CreateTextNode creates a new text node

func (*Document) DocumentElement

func (d *Document) DocumentElement() (types.Node, error)

DocumentElement returns the root node of the document

func (*Document) Dump

func (d *Document) Dump(format bool) string

Dump formats the document with or withour formatting.

func (*Document) Encoding

func (d *Document) Encoding() string

Encoding returns the d

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

func (d *Document) FirstChild() (types.Node, error)

FirstChild returns the document element

func (*Document) Free

func (d *Document) Free()

Free releases the underlying C struct

func (*Document) HasChildNodes

func (d *Document) HasChildNodes() bool

HasChildNodes returns true if the document node is available

func (*Document) IsSameNode

func (d *Document) IsSameNode(n types.Node) bool

IsSameNode checks if the underlying C pointer points to the same C struct

func (*Document) LastChild

func (d *Document) LastChild() (types.Node, error)

LastChild returns the document element

func (*Document) Literal

func (d *Document) Literal() (string, error)

Literal is currently just an alias to Dump(false)

func (*Document) LookupNamespacePrefix

func (d *Document) LookupNamespacePrefix(href string) (string, error)

LookupNamespacePrefix looks for a namespace prefix that matches the given namespace URI

func (*Document) LookupNamespaceURI

func (d *Document) LookupNamespaceURI(prefix string) (string, error)

LookupNamespaceURI looks for a namespace uri that matches the given namespace prefix

func (*Document) MakeMortal

func (d *Document) MakeMortal()

MakeMortal sets the flag

func (*Document) MakePersistent

func (d *Document) MakePersistent()

MakePersistent unsets the flag

func (*Document) NextSibling

func (d *Document) NextSibling() (types.Node, error)

NextSibling always returns nil for Document

func (*Document) NodeName

func (d *Document) NodeName() string

NodeName always returns an empty string for Document

func (*Document) NodeType

func (d *Document) NodeType() clib.XMLNodeType

NodeType returns the XMLNodeType

func (*Document) NodeValue

func (d *Document) NodeValue() string

NodeValue always returns an empty string for Document

func (*Document) OwnerDocument

func (d *Document) OwnerDocument() (types.Document, error)

OwnerDocument always returns the document itself

func (*Document) ParentNode

func (d *Document) ParentNode() (types.Node, error)

ParentNode always returns an error for a document

func (*Document) ParseInContext

func (d *Document) ParseInContext(s string, n int) (types.Node, error)

ParseInContext is currently unimplemented

func (*Document) Pointer

func (d *Document) Pointer() uintptr

Pointer returns the pointer to the underlying C struct

func (*Document) PreviousSibling

func (d *Document) PreviousSibling() (types.Node, error)

PreviousSibling always returns nil for Document

func (*Document) RemoveChild

func (d *Document) RemoveChild(n types.Node) error

func (*Document) SetBaseURI

func (d *Document) SetBaseURI(s string)

SetBaseURI sets the base URI

func (*Document) SetDocument

func (d *Document) SetDocument(n types.Document) error

SetDocument always returns an error for a document

func (*Document) SetDocumentElement

func (d *Document) SetDocumentElement(n types.Node) error

SetDocumentElement sets the document element

func (*Document) SetEncoding

func (d *Document) SetEncoding(e string)

SetEncoding sets the encoding of the document

func (*Document) SetNodeName

func (d *Document) SetNodeName(s string)

SetNodeName is a no op for document

func (*Document) SetNodeValue

func (d *Document) SetNodeValue(s string)

SetNodeValue is a no op for document

func (*Document) SetStandalone

func (d *Document) SetStandalone(v int)

SetStandalone sets the standalone flag

func (*Document) SetVersion

func (d *Document) SetVersion(v string)

SetVersion sets the version of the document

func (*Document) Standalone

func (d *Document) Standalone() int

Standalone returns the value of the standalone flag

func (*Document) String

func (d *Document) String() string

String formats the document, always without formatting.

func (*Document) TextContent

func (d *Document) TextContent() string

TextContent returns the text content

func (*Document) ToString

func (d *Document) ToString(x int, b bool) string

ToString is currently just an alias to Dump(false)

func (*Document) URI

func (d *Document) URI() string

URI returns the document URI

func (*Document) Version

func (d *Document) Version() string

Version returns the version of the document

func (*Document) Walk

func (d *Document) Walk(fn func(types.Node) error) error

Walk traverses the nodes in the document

type Element

type Element struct {
	XMLNode
}

func (*Element) AppendText

func (n *Element) AppendText(s string) error

AppendText adds a new text node

func (*Element) Attributes

func (n *Element) Attributes() ([]types.Attribute, error)

Attributes returns a list of attributes on a node

func (*Element) GetAttribute

func (n *Element) GetAttribute(name string) (types.Attribute, error)

GetAttribute retrieves the value of an attribute

func (*Element) GetNamespaces

func (n *Element) GetNamespaces() ([]types.Namespace, error)

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

func (n Element) Literal() (string, error)

Literal returns a stringified version of this node and its children, inclusive.

func (*Element) RemoveAttribute

func (n *Element) RemoveAttribute(name string) error

RemoveAttribute completely removes an attribute from the node

func (*Element) SetAttribute

func (n *Element) SetAttribute(name, value string) error

SetAttribute sets an attribute

func (*Element) SetNamespace

func (n *Element) SetNamespace(uri, prefix string, activate ...bool) error

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
}

func (*Namespace) Free

func (n *Namespace) Free()

Free releases the underlying C struct

func (*Namespace) Prefix

func (n *Namespace) Prefix() string

Prefix returns the prefix for this namespace

func (*Namespace) URI

func (n *Namespace) URI() string

URI returns the namespace URL

type Pi

type Pi struct {
	XMLNode
}

type Serializer

type Serializer interface {
	Serialize(interface{}) (string, error)
}

type Text

type Text struct {
	XMLNode
}

func (*Text) Data

func (n *Text) Data() string

Data returns the content associated with this node

type XMLNode

type XMLNode struct {
	// contains filtered or unexported fields
}

func (*XMLNode) AddChild

func (n *XMLNode) AddChild(child types.Node) error

AddChild appends the node

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

func (n *XMLNode) ChildNodes() (types.NodeList, error)

ChildNodes returns the child nodes

func (*XMLNode) Copy

func (n *XMLNode) Copy() (types.Node, error)

Copy creates a copy of the node

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

func (n *XMLNode) FirstChild() (types.Node, error)

FirstChild reutrns the first child node

func (*XMLNode) Free

func (n *XMLNode) Free()

Free releases the underlying C struct

func (*XMLNode) HasChildNodes

func (n *XMLNode) HasChildNodes() bool

HasChildNodes returns true if the node contains children

func (*XMLNode) IsSameNode

func (n *XMLNode) IsSameNode(other types.Node) bool

IsSameNode returns true if two nodes point to the same node

func (*XMLNode) LastChild

func (n *XMLNode) LastChild() (types.Node, error)

LastChild returns the last child node

func (XMLNode) Literal

func (n XMLNode) Literal() (string, error)

Literal returns the literal string value

func (*XMLNode) LocalName

func (n *XMLNode) LocalName() string

LocalName returns the local name

func (*XMLNode) LookupNamespacePrefix

func (n *XMLNode) LookupNamespacePrefix(href string) (string, error)

LookupNamespacePrefix returns the prefix associated with the given URL

func (*XMLNode) LookupNamespaceURI

func (n *XMLNode) LookupNamespaceURI(prefix string) (string, error)

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

func (n *XMLNode) NamespaceURI() string

NamespaceURI returns the namespace URI associated with this node

func (*XMLNode) NextSibling

func (n *XMLNode) NextSibling() (types.Node, error)

NextSibling returns the next sibling

func (*XMLNode) NodeName

func (n *XMLNode) NodeName() string

NodeName returns the node name

func (*XMLNode) NodeType

func (n *XMLNode) NodeType() clib.XMLNodeType

NodeType returns the XMLNodeType

func (*XMLNode) NodeValue

func (n *XMLNode) NodeValue() string

NodeValue returns the node value

func (*XMLNode) OwnerDocument

func (n *XMLNode) OwnerDocument() (types.Document, error)

OwnerDocument returns the Document that this node belongs to

func (*XMLNode) ParentNode

func (n *XMLNode) ParentNode() (types.Node, error)

ParentNode returns the parent node

func (*XMLNode) ParseInContext

func (n *XMLNode) ParseInContext(s string, o int) (types.Node, error)

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) Pointer

func (n *XMLNode) Pointer() uintptr

Pointer returns the pointer to the underlying C struct

func (*XMLNode) Prefix

func (n *XMLNode) Prefix() string

Prefix returns the prefix from the node name, if any

func (*XMLNode) PreviousSibling

func (n *XMLNode) PreviousSibling() (types.Node, error)

PreviousSibling returns the previous sibling

func (*XMLNode) RemoveChild

func (n *XMLNode) RemoveChild(t types.Node) error

func (*XMLNode) SetDocument

func (n *XMLNode) SetDocument(d types.Document) error

SetDocument sets the document of this node and its descendants

func (*XMLNode) SetNodeName

func (n *XMLNode) SetNodeName(name string)

SetNodeName sets the node name

func (*XMLNode) SetNodeValue

func (n *XMLNode) SetNodeValue(value string)

SetNodeValue sets the node value

func (*XMLNode) String

func (n *XMLNode) String() string

String returns the string representation

func (*XMLNode) TextContent

func (n *XMLNode) TextContent() string

TextContent returns the text content

func (*XMLNode) ToString

func (n *XMLNode) ToString(format int, docencoding bool) string

ToString returns the string representation. (But it should probably be deprecated)

func (*XMLNode) Walk

func (n *XMLNode) Walk(fn func(types.Node) error) error

Walk traverses through all of the nodes

type XMLNodeType

type XMLNodeType clib.XMLNodeType

XMLNodeType identifies the type of the underlying C struct

Jump to

Keyboard shortcuts

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