W3cubDocs

/Nim

Module xmldom

This module implements XML DOM Level 2 Core specification (http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html)

Imports

strutils

Types

EDOMException = object of ValueError
Base exception object for all DOM Exceptions
EDOMStringSizeErr = object of EDOMException
If the specified range of text does not fit into a DOMString Currently not used(Since DOMString is just string)
EHierarchyRequestErr = object of EDOMException
If any node is inserted somewhere it doesn't belong
EIndexSizeErr = object of EDOMException
If index or size is negative, or greater than the allowed value
EInuseAttributeErr = object of EDOMException
If an attempt is made to add an attribute that is already in use elsewhere
EInvalidAccessErr = object of EDOMException
If a parameter or an operation is not supported by the underlying object.
EInvalidCharacterErr = object of EDOMException
This exception is raised when a string parameter contains an illegal character
EInvalidModificationErr = object of EDOMException
If an attempt is made to modify the type of the underlying object.
EInvalidStateErr = object of EDOMException
If an attempt is made to use an object that is not, or is no longer, usable.
ENamespaceErr = object of EDOMException
If an attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
ENotFoundErr = object of EDOMException
If an attempt is made to reference a node in a context where it does not exist
ENotSupportedErr = object of EDOMException
If the implementation does not support the requested type of object or operation.
ENoDataAllowedErr = object of EDOMException
If data is specified for a node which does not support data
ENoModificationAllowedErr = object of EDOMException
If an attempt is made to modify an object where modifications are not allowed
ESyntaxErr = object of EDOMException
If an invalid or illegal string is specified.
EWrongDocumentErr = object of EDOMException
If a node is used in a different document than the one that created it (that doesn't support it)
PDOMImplementation = ref DOMImplementation
PNode = ref Node
PElement = ref Element
PCharacterData = ref CharacterData
PDocument = ref Document
PAttr = ref Attr
PDocumentFragment = ref DocumentFragment
PText = ref Text
PComment = ref Comment
PCDataSection = ref CDataSection
PProcessingInstruction = ref ProcessingInstruction

Consts

ElementNode = 1
AttributeNode = 2
TextNode = 3
CDataSectionNode = 4
ProcessingInstructionNode = 7
CommentNode = 8
DocumentNode = 9
DocumentFragmentNode = 11

Procs

proc getDOM(): PDOMImplementation {.raises: [], tags: [].}
Returns a DOMImplementation
proc createDocument(dom: PDOMImplementation; namespaceURI: string;
                   qualifiedName: string): PDocument {.raises: [], tags: [].}
Creates an XML Document object of the specified type with its document element.
proc createDocument(dom: PDOMImplementation; n: PElement): PDocument {.raises: [],
    tags: [].}
Creates an XML Document object of the specified type with its document element.
proc hasFeature(dom: PDOMImplementation; feature: string; version: string = ""): bool {.
    raises: [], tags: [].}
Returns true if this version of the DomImplementation implements feature, otherwise false
proc implementation(doc: PDocument): PDOMImplementation {.raises: [], tags: [].}
proc documentElement(doc: PDocument): PElement {.raises: [], tags: [].}
proc createAttribute(doc: PDocument; name: string): PAttr {.
    raises: [EInvalidCharacterErr], tags: [].}
Creates an Attr of the given name. Note that the Attr instance can then be set on an Element using the setAttributeNode method. To create an attribute with a qualified name and namespace URI, use the createAttributeNS method.
proc createAttributeNS(doc: PDocument; namespaceURI: string; qualifiedName: string): PAttr {.
    raises: [EInvalidCharacterErr, ENamespaceErr], tags: [].}
Creates an attribute of the given qualified name and namespace URI
proc createCDATASection(doc: PDocument; data: string): PCDataSection {.raises: [],
    tags: [].}
Creates a CDATASection node whose value is the specified string.
proc createComment(doc: PDocument; data: string): PComment {.raises: [], tags: [].}
Creates a Comment node given the specified string.
proc createDocumentFragment(doc: PDocument): PDocumentFragment {.raises: [], tags: [].}
Creates an empty DocumentFragment object.
proc createElement(doc: PDocument; tagName: string): PElement {.
    raises: [EInvalidCharacterErr], tags: [].}
Creates an element of the type specified.
proc createElementNS(doc: PDocument; namespaceURI: string; qualifiedName: string): PElement {.
    raises: [ENamespaceErr, EInvalidCharacterErr], tags: [].}
Creates an element of the given qualified name and namespace URI.
proc createProcessingInstruction(doc: PDocument; target: string; data: string): PProcessingInstruction {.
    raises: [EInvalidCharacterErr], tags: [].}
Creates a ProcessingInstruction node given the specified name and data strings.
proc createTextNode(doc: PDocument; data: string): PText {.raises: [], tags: [].}
Creates a Text node given the specified string.
proc getElementsByTagName(doc: PDocument; tagName: string): seq[PNode] {.raises: [],
    tags: [].}
Returns a NodeList of all the Elements with a given tag name in the order in which they are encountered in a preorder traversal of the Document tree.
proc getElementsByTagNameNS(doc: PDocument; namespaceURI: string; localName: string): seq[
    PNode] {.raises: [], tags: [].}
Returns a NodeList of all the Elements with a given localName and namespaceURI in the order in which they are encountered in a preorder traversal of the Document tree.
proc importNode(doc: PDocument; importedNode: PNode; deep: bool): PNode {.
    raises: [ENotSupportedErr], tags: [].}
Imports a node from another document to this document
proc firstChild(n: PNode): PNode {.raises: [], tags: [].}
Returns this node's first child
proc lastChild(n: PNode): PNode {.raises: [], tags: [].}
Returns this node's last child
proc localName(n: PNode): string {.raises: [], tags: [].}
Returns this nodes local name
proc namespaceURI(n: PNode): string {.raises: [], tags: [].}
Returns this nodes namespace URI
proc namespaceURI=(n: PNode; value: string) {.raises: [], tags: [].}
proc nextSibling(n: PNode): PNode {.raises: [], tags: [].}
Returns the next sibling of this node
proc nodeName(n: PNode): string {.raises: [], tags: [].}
Returns the name of this node
proc nodeType(n: PNode): int {.raises: [], tags: [].}
Returns the type of this node
proc ownerDocument(n: PNode): PDocument {.raises: [], tags: [].}
Returns the owner document of this node
proc parentNode(n: PNode): PNode {.raises: [], tags: [].}
Returns the parent node of this node
proc previousSibling(n: PNode): PNode {.raises: [], tags: [].}
Returns the previous sibling of this node
proc prefix=(n: PNode; value: string) {.raises: [EInvalidCharacterErr, ENamespaceErr],
                                   tags: [].}
Modifies the prefix of this node
proc appendChild(n: PNode; newChild: PNode) {.raises: [EHierarchyRequestErr,
    EWrongDocumentErr, ENoModificationAllowedErr], tags: [].}
Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
proc cloneNode(n: PNode; deep: bool): PNode {.raises: [], tags: [].}
Returns a duplicate of this node, if deep is true, Element node's children are copied
proc hasAttributes(n: PNode): bool {.raises: [], tags: [].}
Returns whether this node (if it is an element) has any attributes.
proc hasChildNodes(n: PNode): bool {.raises: [], tags: [].}
Returns whether this node has any children.
proc insertBefore(n: PNode; newChild: PNode; refChild: PNode): PNode {.
    raises: [EWrongDocumentErr], tags: [].}
Inserts the node newChild before the existing child node refChild. If refChild is nil, insert newChild at the end of the list of children.
proc isSupported(n: PNode; feature: string; version: string): bool {.raises: [], tags: [].}
Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
proc normalize(n: PNode) {.raises: [], tags: [].}
Merges all separated TextNodes together, and removes any empty TextNodes
proc removeChild(n: PNode; oldChild: PNode): PNode {.raises: [ENotFoundErr], tags: [].}
Removes the child node indicated by oldChild from the list of children, and returns it.
proc replaceChild(n: PNode; newChild: PNode; oldChild: PNode): PNode {.
    raises: [EWrongDocumentErr, ENotFoundErr], tags: [].}
Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node.
proc getNamedItem(nList: seq[PNode]; name: string): PNode {.raises: [], tags: [].}
Retrieves a node specified by name. If this node cannot be found returns nil
proc getNamedItem(nList: seq[PAttr]; name: string): PAttr {.raises: [], tags: [].}
Retrieves a node specified by name. If this node cannot be found returns nil
proc getNamedItemNS(nList: seq[PNode]; namespaceURI: string; localName: string): PNode {.
    raises: [], tags: [].}
Retrieves a node specified by localName and namespaceURI. If this node cannot be found returns nil
proc getNamedItemNS(nList: seq[PAttr]; namespaceURI: string; localName: string): PAttr {.
    raises: [], tags: [].}
Retrieves a node specified by localName and namespaceURI. If this node cannot be found returns nil
proc item(nList: seq[PNode]; index: int): PNode {.raises: [], tags: [].}
Returns the index th item in the map. If index is greater than or equal to the number of nodes in this map, this returns nil.
proc removeNamedItem(nList: var seq[PNode]; name: string): PNode {.
    raises: [ENotFoundErr], tags: [].}
Removes a node specified by name Raises the ENotFoundErr exception, if the node was not found
proc removeNamedItemNS(nList: var seq[PNode]; namespaceURI: string; localName: string): PNode {.
    raises: [ENotFoundErr], tags: [].}
Removes a node specified by local name and namespace URI
proc setNamedItem(nList: var seq[PNode]; arg: PNode): PNode {.
    raises: [EWrongDocumentErr], tags: [].}
Adds arg as a Node to the NList If a node with the same name is already present in this map, it is replaced by the new one.
proc setNamedItem(nList: var seq[PAttr]; arg: PAttr): PAttr {.
    raises: [EWrongDocumentErr, EInuseAttributeErr], tags: [].}
Adds arg as a Node to the NList If a node with the same name is already present in this map, it is replaced by the new one.
proc setNamedItemNS(nList: var seq[PNode]; arg: PNode): PNode {.
    raises: [EWrongDocumentErr], tags: [].}
Adds a node using its namespaceURI and localName
proc setNamedItemNS(nList: var seq[PAttr]; arg: PAttr): PAttr {.
    raises: [EWrongDocumentErr, EInuseAttributeErr], tags: [].}
Adds a node using its namespaceURI and localName
proc name(a: PAttr): string {.raises: [], tags: [].}
Returns the name of the Attribute
proc specified(a: PAttr): bool {.raises: [], tags: [].}
Specifies whether this attribute was specified in the original document
proc ownerElement(a: PAttr): PElement {.raises: [], tags: [].}
Returns this Attributes owner element
proc tagName(el: PElement): string {.raises: [], tags: [].}
Returns the Element Tag Name
proc getAttribute(el: PNode; name: string): string {.raises: [], tags: [].}
Retrieves an attribute value by name
proc getAttributeNS(el: PNode; namespaceURI: string; localName: string): string {.
    raises: [], tags: [].}
Retrieves an attribute value by localName and namespaceURI
proc getAttributeNode(el: PElement; name: string): PAttr {.raises: [], tags: [].}
Retrieves an attribute node by name To retrieve an attribute node by qualified name and namespace URI, use the getAttributeNodeNS method
proc getAttributeNodeNS(el: PElement; namespaceURI: string; localName: string): PAttr {.
    raises: [], tags: [].}
Retrieves an Attr node by localName and namespaceURI
proc getElementsByTagName(el: PElement; name: string): seq[PNode] {.raises: [], tags: [].}
Returns a NodeList of all descendant Elements of el with a given tag name, in the order in which they are encountered in a preorder traversal of this Element tree If name is *, returns all descendant of el
proc getElementsByTagNameNS(el: PElement; namespaceURI: string; localName: string): seq[
    PNode] {.raises: [], tags: [].}
Returns a NodeList of all the descendant Elements with a given localName and namespaceURI in the order in which they are encountered in a preorder traversal of this Element tree
proc hasAttribute(el: PElement; name: string): bool {.raises: [], tags: [].}
Returns true when an attribute with a given name is specified on this element , false otherwise.
proc hasAttributeNS(el: PElement; namespaceURI: string; localName: string): bool {.
    raises: [], tags: [].}
Returns true when an attribute with a given localName and namespaceURI is specified on this element , false otherwise
proc removeAttribute(el: PElement; name: string) {.raises: [], tags: [].}
Removes an attribute by name
proc removeAttributeNS(el: PElement; namespaceURI: string; localName: string) {.
    raises: [], tags: [].}
Removes an attribute by localName and namespaceURI
proc removeAttributeNode(el: PElement; oldAttr: PAttr): PAttr {.
    raises: [ENotFoundErr], tags: [].}
Removes the specified attribute node If the attribute node cannot be found raises ENotFoundErr
proc setAttributeNode(el: PElement; newAttr: PAttr): PAttr {.
    raises: [EWrongDocumentErr, EInuseAttributeErr], tags: [].}
Adds a new attribute node, if an attribute with the same nodeName is present, it is replaced by the new one and the replaced attribute is returned, otherwise nil is returned.
proc setAttributeNodeNS(el: PElement; newAttr: PAttr): PAttr {.
    raises: [EWrongDocumentErr, EInuseAttributeErr], tags: [].}
Adds a new attribute node, if an attribute with the localName and namespaceURI of newAttr is present, it is replaced by the new one and the replaced attribute is returned, otherwise nil is returned.
proc setAttribute(el: PElement; name: string; value: string) {.
    raises: [EInvalidCharacterErr, EWrongDocumentErr, EInuseAttributeErr], tags: [].}
Adds a new attribute, as specified by name and value If an attribute with that name is already present in the element, its value is changed to be that of the value parameter Raises the EInvalidCharacterErr if the specified name contains illegal characters
proc setAttributeNS(el: PElement; namespaceURI, localName, value: string) {.raises: [
    EInvalidCharacterErr, ENamespaceErr, EWrongDocumentErr, EInuseAttributeErr],
    tags: [].}
Adds a new attribute, as specified by namespaceURI, localName and value.
proc splitData(textNode: PText; offset: int): PText {.raises: [EIndexSizeErr], tags: [].}
Breaks this node into two nodes at the specified offset, keeping both in the tree as siblings.
proc target(pi: PProcessingInstruction): string {.raises: [], tags: [].}
Returns the Processing Instructions target
proc `$`(doc: PDocument): string {.raises: [], tags: [].}
Converts a PDocument object into a string representation of it's XML

© 2006–2017 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/xmldom.html