dom

package module
v0.0.0-...-afea191 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

GoDoc Go Report Card Build Status

XML DOM Implementation for Go

This is a library to programmatically create, read, and modify XML documents using Go without marshaling/unmarshaling them into structures. It somewhat follows the XML DOM specification with the following exceptions:

  • This implementation preserves and exposes XML namespace prefixes
  • Elements can be created with namespaces and prefixes
  • CDATA sections are converted to text nodes

Namespace Normalization

The Document interface has a NormalizeNamespaces() method that should be called before serializing the document. It does the following:

  • If there are elements/attributes with namespaces with no associated prefixes, then it create prefixes for them
  • If there are elements/attributes with prefixes that are not defined, it returns error

Serialization

To parse XML documents, use the Parse function with an xml.Decoder. By changing the Strict and Entities fields of a Decoder, this parser can be used to parse HTML data.

To encode a Document as XML, first call NormalizeNamespaces() function, and then use the Encode function.

Documentation

Index

Constants

View Source
const (
	INDEX_SIZE_ERR              = "INDEX_SIZE"
	DOMSTRING_SIZE_ERR          = "DOMSTRING_SIZE"
	HIERARCHY_REQUEST_ERR       = "HIERARCHY_REQUEST"
	WRONG_DOCUMENT_ERR          = "WRONG_DOCUMENT"
	INVALID_CHARACTER_ERR       = "INVALID_CHARACTER"
	NO_DATA_ALLOWED_ERR         = "NO_DATA_ALLOWED"
	NO_MODIFICATION_ALLOWED_ERR = "NO_MODIFICATION_ALLOWED"
	NOT_FOUND_ERR               = "NOT_FOUND"
	NOT_SUPPORTED_ERR           = "NOT_SUPPORTED"
	INUSE_ATTRIBUTE_ERR         = "INUSE_ATTRIBUTE"
	INVALID_STATE_ERR           = "INVALID_STATE"
	SYNTAX_ERR                  = "SYNTAX"
	INVALID_MODIFICATION_ERR    = "INVALID_MODIFICATION"
	NAMESPACE_ERR               = "NAMESPACE"
	INVALID_ACCESS_ERR          = "INVALID_ACCESS"
	VALIDATION_ERR              = "VALIDATION"
	TYPE_MISMATCH_ERR           = "TYPE_MISMATCH"
	SECURITY_ERR                = "SECURITY"
	NETWORK_ERR                 = "NETWORK"
	ABORT_ERR                   = "ABORT"
	URL_MISMATCH_ERR            = "URL_MISMATCH"
	QUOTA_EXCEEDED_ERR          = "QUOTA_EXCEEDED"
	TIMEOUT_ERR                 = "TIMEOUT"
	INVALID_NODE_TYPE_ERR       = "INVALID_NODE_TYPE"
	DATA_CLONE_ERR              = "DATA_CLONE"
)

Variables

This section is empty.

Functions

func Encode

func Encode(node Node, writer io.Writer) error

Types

type Attr

type Attr interface {
	Node

	// A String representing the local part of the qualified name of the
	// attribute.
	GetLocalName() string

	// Returns the qualified name of an attribute, that is the name of
	// the attribute, with the namespace prefix, if any, in front of
	// it. For example, if the local name is lang and the namespace
	// prefix is xml, the returned qualified name is xml:lang.
	GetName() string

	GetQName() Name

	// The Element the attribute belongs to.
	GetOwnerElement() Element

	// The attribute's value, a string that can be set and get using this
	// property.
	GetValue() string

	SetValue(string)
}

type BasicAttr

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

func (*BasicAttr) AppendChild

func (node *BasicAttr) AppendChild(newNode Node) Node

Append newNode as a child of node

func (*BasicAttr) CloneNode

func (attr *BasicAttr) CloneNode(bool) Node

func (*BasicAttr) Contains

func (node *BasicAttr) Contains(nd Node) bool

Returns true or false value indicating whether or not a node is a descendant of the calling node.

func (*BasicAttr) GetChildNodes

func (node *BasicAttr) GetChildNodes() NodeList

Returns a live NodeList containing all the children of this node (including elements, text and comments). NodeList being live means that if the children of the Node change, the NodeList object is automatically updated.

func (*BasicAttr) GetFirstChild

func (node *BasicAttr) GetFirstChild() Node

Returns a Node representing the first direct child node of the node, or null if the node has no child.

func (*BasicAttr) GetLastChild

func (node *BasicAttr) GetLastChild() Node

Returns a Node representing the last direct child node of the node, or null if the node has no child.

func (*BasicAttr) GetLocalName

func (attr *BasicAttr) GetLocalName() string

A String representing the local part of the qualified name of the attribute.

func (*BasicAttr) GetName

func (attr *BasicAttr) GetName() string

Returns the qualified name of an attribute, that is the name of the attribute, with the namespace prefix, if any, in front of it. For example, if the local name is lang and the namespace prefix is xml, the returned qualified name is xml:lang.

func (*BasicAttr) GetNextSibling

func (node *BasicAttr) GetNextSibling() Node

Returns a Node representing the next node in the tree, or null if there isn't such node.

func (*BasicAttr) GetNodeName

func (attr *BasicAttr) GetNodeName() string

func (*BasicAttr) GetNodeType

func (attr *BasicAttr) GetNodeType() NodeType

func (*BasicAttr) GetOwnerDocument

func (node *BasicAttr) GetOwnerDocument() Document

Returns the Document that this node belongs to. If the node is itself a document, returns null.

func (*BasicAttr) GetOwnerElement

func (attr *BasicAttr) GetOwnerElement() Element

The Element the attribute belongs to.

func (*BasicAttr) GetParentElement

func (node *BasicAttr) GetParentElement() Element

Returns an Element that is the parent of this node. If the node has no parent, or if that parent is not an Element, this property returns null.

func (*BasicAttr) GetParentNode

func (node *BasicAttr) GetParentNode() Node

Returns a Node that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns null.

func (*BasicAttr) GetPreviousSibling

func (node *BasicAttr) GetPreviousSibling() Node

Returns a Node representing the previous node in the tree, or null if there isn't such node.

func (*BasicAttr) GetQName

func (attr *BasicAttr) GetQName() Name

func (*BasicAttr) GetRootNode

func (node *BasicAttr) GetRootNode() Node

func (*BasicAttr) GetValue

func (attr *BasicAttr) GetValue() string

The attribute's value, a string that can be set and get using this property.

func (*BasicAttr) HasChildNodes

func (node *BasicAttr) HasChildNodes() bool

Returns a boolean value indicating whether or not the element has any child nodes.

func (*BasicAttr) InsertBefore

func (node *BasicAttr) InsertBefore(newNode, referenceNode Node) Node

func (*BasicAttr) IsDefaultNamespace

func (node *BasicAttr) IsDefaultNamespace(uri string) bool

Accepts a namespace URI as an argument and returns a boolean value with a value of true if the namespace is the default namespace on the given node or false if not.

func (*BasicAttr) IsEqualNode

func (attr *BasicAttr) IsEqualNode(node Node) bool

Returns a boolean value which indicates whether or not two nodes are of the same type and all their defining data points match.

func (*BasicAttr) IsSameNode

func (attr *BasicAttr) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicAttr) LookupNamespaceURI

func (node *BasicAttr) LookupNamespaceURI(prefix string) string

Accepts a prefix and returns the namespace URI associated with it on the given node if found (and "" if not). Supplying "" for the prefix will return the default namespace.

func (*BasicAttr) LookupPrefix

func (node *BasicAttr) LookupPrefix(uri string) string

Returns a string containing the prefix for a given namespace URI, if present, and "" if not. When multiple prefixes are possible, the result is implementation-dependent.

func (*BasicAttr) Normalize

func (node *BasicAttr) Normalize()

Clean up all the text nodes under this element (merge adjacent, remove empty).

func (*BasicAttr) RemoveChild

func (node *BasicAttr) RemoveChild(child Node)

Remove child from node

func (*BasicAttr) SetValue

func (attr *BasicAttr) SetValue(v string)

type BasicComment

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

func (*BasicComment) AppendChild

func (cd *BasicComment) AppendChild(Node) Node

func (*BasicComment) CloneNode

func (cd *BasicComment) CloneNode(deep bool) Node

func (*BasicComment) GetNodeName

func (cd *BasicComment) GetNodeName() string

Returns "#comment"

func (*BasicComment) GetNodeType

func (cd *BasicComment) GetNodeType() NodeType

Returns COMMENT_NODE

func (*BasicComment) GetValue

func (cd *BasicComment) GetValue() string

func (*BasicComment) HasChildNodes

func (cd *BasicComment) HasChildNodes() bool

func (*BasicComment) InsertBefore

func (cd *BasicComment) InsertBefore(newNode, referenceNode Node) Node

func (*BasicComment) IsEqualNode

func (cd *BasicComment) IsEqualNode(node Node) bool

func (*BasicComment) IsSameNode

func (cd *BasicComment) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicComment) Normalize

func (cs *BasicComment) Normalize()

func (*BasicComment) RemoveChild

func (cs *BasicComment) RemoveChild(Node)

func (*BasicComment) SetValue

func (cd *BasicComment) SetValue(text string)

type BasicDocument

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

BasicDocument implements DOM document

Implementation is guided by https://dom.spec.whatwg.org/

func (*BasicDocument) AdoptNode

func (doc *BasicDocument) AdoptNode(node Node) Node

Adopt node from an external document.

func (*BasicDocument) AppendChild

func (doc *BasicDocument) AppendChild(newNode Node) Node

Append newNode as a child of node

func (*BasicDocument) CloneNode

func (doc *BasicDocument) CloneNode(deep bool) Node

Clone a Node, and optionally, all of its contents.

Returns the new Node cloned. The cloned node has no parent and is not part of the document, until it is added to another node that is part of the document, using Node.appendChild() or a similar method.

func (*BasicDocument) Contains

func (node *BasicDocument) Contains(nd Node) bool

Returns true or false value indicating whether or not a node is a descendant of the calling node.

func (*BasicDocument) CreateAttribute

func (doc *BasicDocument) CreateAttribute(name string) Attr

Creates a new Attr object and returns it.

func (*BasicDocument) CreateAttributeNS

func (doc *BasicDocument) CreateAttributeNS(prefix string, ns string, name string) Attr

Creates a new attribute node in a given namespace and returns it.

func (*BasicDocument) CreateComment

func (doc *BasicDocument) CreateComment(text string) Comment

Creates a comment node.

func (*BasicDocument) CreateElement

func (doc *BasicDocument) CreateElement(tag string) Element

Creates a new element with the given tag name.

func (*BasicDocument) CreateElementNS

func (doc *BasicDocument) CreateElementNS(prefix string, ns string, tag string) Element

Creates a new element with the given tag name and namespace URI.

func (*BasicDocument) CreateProcessingInstruction

func (doc *BasicDocument) CreateProcessingInstruction(target, data string) ProcessingInstruction

Creates a processing instruction node.

func (*BasicDocument) CreateTextNode

func (doc *BasicDocument) CreateTextNode(text string) Text

Creates a text node.

func (*BasicDocument) GetChildNodes

func (node *BasicDocument) GetChildNodes() NodeList

Returns a live NodeList containing all the children of this node (including elements, text and comments). NodeList being live means that if the children of the Node change, the NodeList object is automatically updated.

func (*BasicDocument) GetDocumentElement

func (doc *BasicDocument) GetDocumentElement() Element

Returns the Element that is a direct child of the document.

func (*BasicDocument) GetDocumentType

func (doc *BasicDocument) GetDocumentType() DocumentType

GetDocumentType returns the document type node

func (*BasicDocument) GetFirstChild

func (node *BasicDocument) GetFirstChild() Node

Returns a Node representing the first direct child node of the node, or null if the node has no child.

func (*BasicDocument) GetLastChild

func (node *BasicDocument) GetLastChild() Node

Returns a Node representing the last direct child node of the node, or null if the node has no child.

func (*BasicDocument) GetNextSibling

func (node *BasicDocument) GetNextSibling() Node

Returns a Node representing the next node in the tree, or null if there isn't such node.

func (*BasicDocument) GetNodeName

func (doc *BasicDocument) GetNodeName() string

Returns "#document"

func (*BasicDocument) GetNodeType

func (doc *BasicDocument) GetNodeType() NodeType

Returns DOCUMENT_NODE

func (*BasicDocument) GetOwnerDocument

func (node *BasicDocument) GetOwnerDocument() Document

Returns the Document that this node belongs to. If the node is itself a document, returns null.

func (*BasicDocument) GetParentElement

func (node *BasicDocument) GetParentElement() Element

Returns an Element that is the parent of this node. If the node has no parent, or if that parent is not an Element, this property returns null.

func (*BasicDocument) GetParentNode

func (node *BasicDocument) GetParentNode() Node

Returns a Node that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns null.

func (*BasicDocument) GetPreviousSibling

func (node *BasicDocument) GetPreviousSibling() Node

Returns a Node representing the previous node in the tree, or null if there isn't such node.

func (*BasicDocument) GetRootNode

func (node *BasicDocument) GetRootNode() Node

func (*BasicDocument) HasChildNodes

func (node *BasicDocument) HasChildNodes() bool

Returns a boolean value indicating whether or not the element has any child nodes.

func (*BasicDocument) InsertBefore

func (doc *BasicDocument) InsertBefore(newNode, referenceNode Node) Node

func (*BasicDocument) IsDefaultNamespace

func (doc *BasicDocument) IsDefaultNamespace(uri string) bool

Accepts a namespace URI as an argument and returns a boolean value with a value of true if the namespace is the default namespace on the given node or false if not.

func (*BasicDocument) IsEqualNode

func (doc *BasicDocument) IsEqualNode(node Node) bool

Returns a boolean value which indicates whether or not two nodes are of the same type and all their defining data points match.

func (*BasicDocument) IsSameNode

func (doc *BasicDocument) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicDocument) LookupNamespaceURI

func (doc *BasicDocument) LookupNamespaceURI(prefix string) string

Accepts a prefix and returns the namespace URI associated with it on the given node if found (and "" if not).

func (*BasicDocument) LookupPrefix

func (doc *BasicDocument) LookupPrefix(uri string) string

Returns a string containing the prefix for a given namespace URI, if present, and "" if not. When multiple prefixes are possible, the result is implementation-dependent.

func (*BasicDocument) Normalize

func (doc *BasicDocument) Normalize()

Clean up all the text nodes under this element (merge adjacent, remove empty).

func (*BasicDocument) NormalizeNamespaces

func (doc *BasicDocument) NormalizeNamespaces() error

NormalizeNamespaces assigns missing namespace prefixes

func (*BasicDocument) RemoveChild

func (doc *BasicDocument) RemoveChild(child Node)

Remove child from node

type BasicDocumentType

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

func (*BasicDocumentType) AppendChild

func (node *BasicDocumentType) AppendChild(newNode Node) Node

Append newNode as a child of node

func (*BasicDocumentType) CloneNode

func (node *BasicDocumentType) CloneNode(bool) Node

func (*BasicDocumentType) Contains

func (node *BasicDocumentType) Contains(nd Node) bool

Returns true or false value indicating whether or not a node is a descendant of the calling node.

func (*BasicDocumentType) GetChildNodes

func (node *BasicDocumentType) GetChildNodes() NodeList

Returns a live NodeList containing all the children of this node (including elements, text and comments). NodeList being live means that if the children of the Node change, the NodeList object is automatically updated.

func (*BasicDocumentType) GetDefinition

func (dt *BasicDocumentType) GetDefinition() string

func (*BasicDocumentType) GetFirstChild

func (node *BasicDocumentType) GetFirstChild() Node

Returns a Node representing the first direct child node of the node, or null if the node has no child.

func (*BasicDocumentType) GetLastChild

func (node *BasicDocumentType) GetLastChild() Node

Returns a Node representing the last direct child node of the node, or null if the node has no child.

func (*BasicDocumentType) GetName

func (dt *BasicDocumentType) GetName() string

func (*BasicDocumentType) GetNextSibling

func (node *BasicDocumentType) GetNextSibling() Node

Returns a Node representing the next node in the tree, or null if there isn't such node.

func (*BasicDocumentType) GetNodeName

func (node *BasicDocumentType) GetNodeName() string

func (*BasicDocumentType) GetNodeType

func (dt *BasicDocumentType) GetNodeType() NodeType

func (*BasicDocumentType) GetOwnerDocument

func (node *BasicDocumentType) GetOwnerDocument() Document

Returns the Document that this node belongs to. If the node is itself a document, returns null.

func (*BasicDocumentType) GetParentElement

func (node *BasicDocumentType) GetParentElement() Element

Returns an Element that is the parent of this node. If the node has no parent, or if that parent is not an Element, this property returns null.

func (*BasicDocumentType) GetParentNode

func (node *BasicDocumentType) GetParentNode() Node

Returns a Node that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns null.

func (*BasicDocumentType) GetPreviousSibling

func (node *BasicDocumentType) GetPreviousSibling() Node

Returns a Node representing the previous node in the tree, or null if there isn't such node.

func (*BasicDocumentType) GetPublicID

func (dt *BasicDocumentType) GetPublicID() string

func (*BasicDocumentType) GetRootNode

func (node *BasicDocumentType) GetRootNode() Node

func (*BasicDocumentType) GetSystemID

func (dt *BasicDocumentType) GetSystemID() string

func (*BasicDocumentType) HasChildNodes

func (node *BasicDocumentType) HasChildNodes() bool

Returns a boolean value indicating whether or not the element has any child nodes.

func (*BasicDocumentType) InsertBefore

func (node *BasicDocumentType) InsertBefore(newNode, referenceNode Node) Node

func (*BasicDocumentType) IsDefaultNamespace

func (node *BasicDocumentType) IsDefaultNamespace(uri string) bool

Accepts a namespace URI as an argument and returns a boolean value with a value of true if the namespace is the default namespace on the given node or false if not.

func (*BasicDocumentType) IsEqualNode

func (node *BasicDocumentType) IsEqualNode(Node) bool

func (*BasicDocumentType) IsSameNode

func (node *BasicDocumentType) IsSameNode(Node) bool

func (*BasicDocumentType) LookupNamespaceURI

func (node *BasicDocumentType) LookupNamespaceURI(prefix string) string

Accepts a prefix and returns the namespace URI associated with it on the given node if found (and "" if not). Supplying "" for the prefix will return the default namespace.

func (*BasicDocumentType) LookupPrefix

func (node *BasicDocumentType) LookupPrefix(uri string) string

Returns a string containing the prefix for a given namespace URI, if present, and "" if not. When multiple prefixes are possible, the result is implementation-dependent.

func (*BasicDocumentType) Normalize

func (node *BasicDocumentType) Normalize()

Clean up all the text nodes under this element (merge adjacent, remove empty).

func (*BasicDocumentType) RemoveChild

func (node *BasicDocumentType) RemoveChild(child Node)

Remove child from node

type BasicElement

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

func (*BasicElement) AppendChild

func (el *BasicElement) AppendChild(newNode Node) Node

Append newNode as a child of node

func (*BasicElement) CloneNode

func (el *BasicElement) CloneNode(deep bool) Node

func (*BasicElement) Contains

func (node *BasicElement) Contains(nd Node) bool

Returns true or false value indicating whether or not a node is a descendant of the calling node.

func (*BasicElement) GetAttribute

func (el *BasicElement) GetAttribute(name string) (string, bool)

Retrieves the value of the named attribute from the current node and returns it as a string.

func (*BasicElement) GetAttributeNS

func (el *BasicElement) GetAttributeNS(uri string, name string) (string, bool)

Retrieves the value of the attribute with the specified namespace and name from the current node and returns it as a string.

func (*BasicElement) GetAttributeNames

func (el *BasicElement) GetAttributeNames() []string

Returns an array of attribute names from the current element.

func (*BasicElement) GetAttributeNode

func (el *BasicElement) GetAttributeNode(name string) Attr

Retrieves the node representation of the named attribute from the current node and returns it as an Attr.

func (*BasicElement) GetAttributeNodeNS

func (el *BasicElement) GetAttributeNodeNS(uri, name string) Attr

Retrieves the node representation of the attribute with the specified name and namespace, from the current node and returns it as an Attr.

func (*BasicElement) GetAttributes

func (el *BasicElement) GetAttributes() NamedNodeMap

func (*BasicElement) GetChildNodes

func (node *BasicElement) GetChildNodes() NodeList

Returns a live NodeList containing all the children of this node (including elements, text and comments). NodeList being live means that if the children of the Node change, the NodeList object is automatically updated.

func (*BasicElement) GetFirstChild

func (node *BasicElement) GetFirstChild() Node

Returns a Node representing the first direct child node of the node, or null if the node has no child.

func (*BasicElement) GetFirstElementChild

func (el *BasicElement) GetFirstElementChild() Element

func (*BasicElement) GetLastChild

func (node *BasicElement) GetLastChild() Node

Returns a Node representing the last direct child node of the node, or null if the node has no child.

func (*BasicElement) GetLastElementChild

func (el *BasicElement) GetLastElementChild() Element

func (*BasicElement) GetLocalName

func (el *BasicElement) GetLocalName() string

A string representing the local part of the qualified name of the element.

func (*BasicElement) GetNextElementSibling

func (el *BasicElement) GetNextElementSibling() Element

func (*BasicElement) GetNextSibling

func (node *BasicElement) GetNextSibling() Node

Returns a Node representing the next node in the tree, or null if there isn't such node.

func (*BasicElement) GetNodeName

func (el *BasicElement) GetNodeName() string

Returns HTML uppercased qualified name

func (*BasicElement) GetNodeType

func (el *BasicElement) GetNodeType() NodeType

Returns ELEMENT_NODE

func (*BasicElement) GetOwnerDocument

func (node *BasicElement) GetOwnerDocument() Document

Returns the Document that this node belongs to. If the node is itself a document, returns null.

func (*BasicElement) GetParentElement

func (node *BasicElement) GetParentElement() Element

Returns an Element that is the parent of this node. If the node has no parent, or if that parent is not an Element, this property returns null.

func (*BasicElement) GetParentNode

func (node *BasicElement) GetParentNode() Node

Returns a Node that is the parent of this node. If there is no such node, like if this node is the top of the tree or if doesn't participate in a tree, this property returns null.

func (*BasicElement) GetPrefix

func (el *BasicElement) GetPrefix() string

Returns a string representing the namespace prefix of the element, or "" if no prefix is specified.

func (*BasicElement) GetPreviousElementSibling

func (el *BasicElement) GetPreviousElementSibling() Element

func (*BasicElement) GetPreviousSibling

func (node *BasicElement) GetPreviousSibling() Node

Returns a Node representing the previous node in the tree, or null if there isn't such node.

func (*BasicElement) GetQName

func (el *BasicElement) GetQName() Name

func (*BasicElement) GetRootNode

func (node *BasicElement) GetRootNode() Node

func (*BasicElement) GetTagName

func (el *BasicElement) GetTagName() string

Returns a String with the name of the tag for the given element.

func (*BasicElement) HasAttribute

func (el *BasicElement) HasAttribute(name string) bool

Returns a boolean value indicating if the element has the specified attribute or not.

func (*BasicElement) HasAttributeNS

func (el *BasicElement) HasAttributeNS(uri string, name string) bool

Returns a boolean value indicating if the element has the specified attribute, in the specified namespace, or not.

func (*BasicElement) HasChildNodes

func (node *BasicElement) HasChildNodes() bool

Returns a boolean value indicating whether or not the element has any child nodes.

func (*BasicElement) InsertBefore

func (el *BasicElement) InsertBefore(newNode, referenceNode Node) Node

func (*BasicElement) IsDefaultNamespace

func (el *BasicElement) IsDefaultNamespace(uri string) bool

Accepts a namespace URI as an argument and returns a boolean value with a value of true if the namespace is the default namespace on the given node or false if not.

func (*BasicElement) IsEqualNode

func (el *BasicElement) IsEqualNode(node Node) bool

func (*BasicElement) IsSameNode

func (el *BasicElement) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicElement) LookupNamespaceURI

func (el *BasicElement) LookupNamespaceURI(prefix string) string

Accepts a prefix and returns the namespace URI associated with it on the given node if found (and "" if not). Supplying "" for the prefix will return the default namespace.

func (*BasicElement) LookupPrefix

func (el *BasicElement) LookupPrefix(uri string) string

Returns a string containing the prefix for a given namespace URI, if present, and "" if not. When multiple prefixes are possible, the result is implementation-dependent.

func (*BasicElement) Normalize

func (el *BasicElement) Normalize()

func (*BasicElement) Remove

func (el *BasicElement) Remove()

Removes the element from the children list of its parent.

func (*BasicElement) RemoveAttribute

func (el *BasicElement) RemoveAttribute(name string)

Removes the named attribute from the current node.

func (*BasicElement) RemoveAttributeNS

func (el *BasicElement) RemoveAttributeNS(uri string, name string)

Removes the attribute with the specified name and namespace, from the current node.

func (*BasicElement) RemoveAttributeNode

func (el *BasicElement) RemoveAttributeNode(attr Attr)

Removes the node representation of the named attribute from the current node.

func (*BasicElement) RemoveChild

func (el *BasicElement) RemoveChild(child Node)

Remove child from node

func (*BasicElement) SetAttribute

func (el *BasicElement) SetAttribute(name string, value string)

Sets the value of a named attribute of the current node.

func (*BasicElement) SetAttributeNS

func (el *BasicElement) SetAttributeNS(prefix, uri, name string, value string)

Sets the value of the attribute with the specified name and namespace, from the current node.

func (*BasicElement) SetAttributeNode

func (el *BasicElement) SetAttributeNode(attr Attr)

Sets the node representation of the named attribute from the current node.

func (*BasicElement) SetAttributeNodeNS

func (el *BasicElement) SetAttributeNodeNS(attr Attr)

Sets the node representation of the attribute with the specified name and namespace, from the current node.

type BasicNamedNodeMap

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

func (*BasicNamedNodeMap) GetLength

func (b *BasicNamedNodeMap) GetLength() int

func (*BasicNamedNodeMap) GetNamedItemNS

func (b *BasicNamedNodeMap) GetNamedItemNS(uri string, name string) Attr

Returns a Attr identified by a namespace and related local name.

func (*BasicNamedNodeMap) Item

func (b *BasicNamedNodeMap) Item(i int) Attr

Returns the Attr at the given index, or null if the index is higher or equal to the number of nodes

func (*BasicNamedNodeMap) RemoveNamedItemNS

func (b *BasicNamedNodeMap) RemoveNamedItemNS(uri string, name string)

func (*BasicNamedNodeMap) SetNamedItemNS

func (b *BasicNamedNodeMap) SetNamedItemNS(a Attr)

Replaces, or adds, the Attr identified in the map by the given namespace and related local name.

type BasicNodeList

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

func (*BasicNodeList) GetLength

func (list *BasicNodeList) GetLength() int

func (*BasicNodeList) Item

func (list *BasicNodeList) Item(i int) Node

type BasicProcessingInstruction

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

func (*BasicProcessingInstruction) AppendChild

func (cd *BasicProcessingInstruction) AppendChild(Node) Node

func (*BasicProcessingInstruction) CloneNode

func (p *BasicProcessingInstruction) CloneNode(deep bool) Node

func (*BasicProcessingInstruction) GetNodeName

func (p *BasicProcessingInstruction) GetNodeName() string

Returns target

func (*BasicProcessingInstruction) GetNodeType

func (p *BasicProcessingInstruction) GetNodeType() NodeType

Returns PROCESSING_INSTRUCTION_NODE

func (*BasicProcessingInstruction) GetTarget

func (p *BasicProcessingInstruction) GetTarget() string

func (*BasicProcessingInstruction) GetValue

func (cd *BasicProcessingInstruction) GetValue() string

func (*BasicProcessingInstruction) HasChildNodes

func (cd *BasicProcessingInstruction) HasChildNodes() bool

func (*BasicProcessingInstruction) InsertBefore

func (cd *BasicProcessingInstruction) InsertBefore(newNode, referenceNode Node) Node

func (*BasicProcessingInstruction) IsEqualNode

func (p *BasicProcessingInstruction) IsEqualNode(node Node) bool

func (*BasicProcessingInstruction) IsSameNode

func (p *BasicProcessingInstruction) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicProcessingInstruction) Normalize

func (cs *BasicProcessingInstruction) Normalize()

func (*BasicProcessingInstruction) RemoveChild

func (cs *BasicProcessingInstruction) RemoveChild(Node)

func (*BasicProcessingInstruction) SetTarget

func (p *BasicProcessingInstruction) SetTarget(t string)

func (*BasicProcessingInstruction) SetValue

func (cd *BasicProcessingInstruction) SetValue(text string)

type BasicText

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

func (*BasicText) AppendChild

func (cd *BasicText) AppendChild(Node) Node

func (*BasicText) CloneNode

func (cd *BasicText) CloneNode(deep bool) Node

func (*BasicText) GetNodeName

func (cd *BasicText) GetNodeName() string

Returns "#text"

func (*BasicText) GetNodeType

func (cd *BasicText) GetNodeType() NodeType

Returns TEXT_NODE

func (*BasicText) GetValue

func (cd *BasicText) GetValue() string

func (*BasicText) HasChildNodes

func (cd *BasicText) HasChildNodes() bool

func (*BasicText) InsertBefore

func (cd *BasicText) InsertBefore(newNode, referenceNode Node) Node

func (*BasicText) IsEqualNode

func (cd *BasicText) IsEqualNode(node Node) bool

func (*BasicText) IsSameNode

func (cd *BasicText) IsSameNode(node Node) bool

Returns a boolean value indicating whether or not the two nodes are the same (that is, they reference the same object).

func (*BasicText) Normalize

func (cs *BasicText) Normalize()

func (*BasicText) RemoveChild

func (cs *BasicText) RemoveChild(Node)

func (*BasicText) SetValue

func (cd *BasicText) SetValue(text string)

type CharacterData

type CharacterData interface {
	Node

	GetValue() string
	SetValue(string)
}

type Comment

type Comment interface {
	CharacterData
}

type Document

type Document interface {
	Node

	// Returns the Element that is a direct child of the document.
	GetDocumentElement() Element

	// Creates a new Attr object and returns it.
	CreateAttribute(string) Attr

	// Creates a new attribute node in a given namespace and returns it.
	CreateAttributeNS(prefix string, ns string, name string) Attr

	// Creates a new comment node and returns it.
	CreateComment(string) Comment

	// Creates a new element with the given tag name.
	CreateElement(string) Element

	// Creates a new element with the given tag name and namespace URI.
	CreateElementNS(prefix string, ns string, tag string) Element

	// Creates a text node.
	CreateTextNode(string) Text

	//Creates a new ProcessingInstruction object.
	CreateProcessingInstruction(target, data string) ProcessingInstruction

	// Assigns missing namespace prefixes, resolve prefix clashes etc.
	NormalizeNamespaces() error

	//	Adopt node from an external document.
	AdoptNode(Node) Node

	// Return the document type node
	GetDocumentType() DocumentType
}

func NewDocument

func NewDocument() Document

func Parse

func Parse(decoder *xml.Decoder) (ret Document, resultErr error)

Parses an XML document.

If decoder.Strict is false, the parser looks at decoder.AutoClose to handle auto-closing HTML tags. Otherwise it is a strict XML parser.

type DocumentType

type DocumentType interface {
	Node

	GetName() string
	GetPublicID() string
	GetSystemID() string
	GetDefinition() string
}

func ParseDocumentType

func ParseDocumentType(content []byte) (DocumentType, bool, error)

ParseDocumentType parses a document type starting with <!DOCTYPE ... If the input is not a doctype, returns nil,false,nil

type Element

type Element interface {
	Node

	GetAttributes() NamedNodeMap

	// Returns a String with the name of the tag for the given element.
	GetTagName() string

	// GetQName returns the qualified name
	GetQName() Name

	// Returns a string representing the namespace prefix of the element,
	// or "" if no prefix is specified.
	GetPrefix() string

	// A string representing the local part of the qualified name of the
	// element.
	GetLocalName() string

	GetFirstElementChild() Element
	GetLastElementChild() Element
	GetNextElementSibling() Element
	GetPreviousElementSibling() Element

	// Retrieves the value of the named attribute from the current node
	// and returns it as a string.
	GetAttribute(string) (string, bool)

	// Returns an array of attribute names from the current element.
	GetAttributeNames() []string

	// Retrieves the node representation of the named attribute from the
	// current node and returns it as an Attr.
	GetAttributeNode(string) Attr

	// Retrieves the node representation of the attribute with the
	// specified name and namespace, from the current node and returns
	// it as an Attr.
	GetAttributeNodeNS(uri, name string) Attr

	//	Retrieves the value of the attribute with the specified
	//	namespace and name from the current node and returns it as a
	//	string.
	GetAttributeNS(uri string, name string) (string, bool)

	// Returns a boolean value indicating if the element has the
	// specified attribute or not.
	HasAttribute(string) bool

	// Removes the element from the children list of its parent.
	Remove()

	// Removes the named attribute from the current node.
	RemoveAttribute(string)

	// Removes the node representation of the named attribute from the
	// current node.
	RemoveAttributeNode(Attr)

	// Removes the attribute with the specified name and namespace, from
	// the current node.
	RemoveAttributeNS(uri string, name string)

	// Sets the value of a named attribute of the current node.
	SetAttribute(name string, value string)

	// Sets the node representation of the named attribute from the
	// current node.
	SetAttributeNode(attr Attr)

	// Sets the value of the attribute with the specified name and
	// namespace, from the current node.
	SetAttributeNS(prefix, uri, name string, value string)
}

type ErrDOM

type ErrDOM struct {
	Typ string
	Msg string
	Op  string
}

func ErrHierarchyRequest

func ErrHierarchyRequest(op, msg string) ErrDOM

func (ErrDOM) Error

func (e ErrDOM) Error() string

type Name

type Name struct {
	xml.Name
	// Namespace prefix
	Prefix string
}

func (*Name) QName

func (name *Name) QName() string

type NamedNodeMap

type NamedNodeMap interface {
	GetLength() int

	// Returns the Attr at the given index, or null if the index is higher or equal to the number of nodes
	Item(int) Attr

	// Returns a Attr identified by a namespace and related local name.
	GetNamedItemNS(uri, name string) Attr

	// Replaces, or adds, the Attr identified in the map by the given namespace and related local name.
	SetNamedItemNS(Attr)

	RemoveNamedItemNS(uri string, name string)
}

type Node

type Node interface {
	// Returns a live NodeList containing all the children of this node
	// (including elements, text and comments). NodeList being live means
	// that if the children of the Node change, the NodeList object is
	// automatically updated.
	GetChildNodes() NodeList

	// Returns a Node representing the first direct child node of the
	// node, or null if the node has no child.
	GetFirstChild() Node

	// Returns a Node representing the last direct child node of the node,
	// or null if the node has no child.
	GetLastChild() Node

	// Returns a Node representing the next node in the tree, or null if
	// there isn't such node.
	GetNextSibling() Node

	// Returns a String containing the name of the Node. The structure of
	// the name will differ with the node type. E.g. An HTMLElement will
	// contain the name of the corresponding tag, like 'audio' for an
	// HTMLAudioElement, a Text node will have the '#text' string, or a
	// Document node will have the '#document' string.
	GetNodeName() string

	// Returns an unsigned short representing the type of the
	// node.
	GetNodeType() NodeType

	// Returns the Document that this node belongs to. If the node is
	// itself a document, returns null.
	GetOwnerDocument() Document

	// Returns a Node that is the parent of this node. If there is no such
	// node, like if this node is the top of the tree or if doesn't
	// participate in a tree, this property returns null.
	GetParentNode() Node

	// Returns an Element that is the parent of this node. If the node has
	// no parent, or if that parent is not an Element, this property
	// returns null.
	GetParentElement() Element

	// Returns a Node representing the previous node in the tree, or null
	// if there isn't such node.
	GetPreviousSibling() Node

	// Adds the specified childNode argument as the last child to the
	// current node. If the argument referenced an existing node on the
	// DOM tree, the node will be detached from its current position and
	// attached at the new position.
	//
	// Returns a Node that is the appended child (aChild), except when aChild
	// is a DocumentFragment, in which case the empty DocumentFragment
	// is returned.
	AppendChild(Node) Node

	// Returns a boolean value indicating whether or not the element has
	// any child nodes.
	HasChildNodes() bool

	// Return node.
	InsertBefore(newNode, referenceNode Node) Node

	// Removes a child node from the current element, which must be a
	// child of the current node.
	RemoveChild(Node)

	// Clone a Node, and optionally, all of its contents.
	//
	// Returns the new Node cloned. The cloned node has no parent and is not
	// part of the document, until it is added to another node that is
	// part of the document, using Node.appendChild() or a similar
	// method.
	CloneNode(deep bool) Node

	// Returns true or false value indicating whether or not a node is a
	// descendant of the calling node.
	Contains(Node) bool

	// Returns the object's root
	GetRootNode() Node

	// Accepts a namespace URI as an argument and returns a boolean value
	// with a value of true if the namespace is the default namespace on
	// the given node or false if not.
	IsDefaultNamespace(uri string) bool

	// Returns a boolean value which indicates whether or not two nodes
	// are of the same type and all their defining data points match.
	IsEqualNode(Node) bool

	// Returns a boolean value indicating whether or not the two nodes are
	// the same (that is, they reference the same object).
	IsSameNode(Node) bool

	// Returns a string  containing the prefix for a given namespace
	// URI, if present, and "" if not. When multiple prefixes are
	// possible, the result is implementation-dependent.
	LookupPrefix(string) string

	// Accepts a prefix and returns the namespace URI associated with it
	// on the given node if found (and "" if not).
	LookupNamespaceURI(string) string

	// Clean up all the text nodes under this element (merge adjacent,
	// remove empty).
	Normalize()
	// contains filtered or unexported methods
}

type NodeList

type NodeList interface {
	GetLength() int
	Item(int) Node
}

type NodeType

type NodeType uint
const ATTRIBUTE_NODE NodeType = 2
const CDATA_SECTION_NODE NodeType = 4
const COMMENT_NODE NodeType = 8
const DOCUMENT_FRAGMENT_NODE NodeType = 11
const DOCUMENT_NODE NodeType = 9
const DOCUMENT_TYPE_NODE NodeType = 10
const ELEMENT_NODE NodeType = 1
const PROCESSING_INSTRUCTION_NODE NodeType = 7
const TEXT_NODE NodeType = 3

type ProcessingInstruction

type ProcessingInstruction interface {
	CharacterData

	GetTarget() string
	SetTarget(string)
}

type Text

type Text interface {
	CharacterData
}

Jump to

Keyboard shortcuts

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