-
Notifications
You must be signed in to change notification settings - Fork 0
Element
The Element class represents an element node in the XML tree. Inherits from Node
Creates a new element object called name with attrs as its attributes. It is recommended that you use the node method of Document or Element instead.
args doc - a document object to provide context for the node name - a string representing the name of the element content - a string representing the content to add to the node
Get the name of the element
returns - a string representing the name of the element
Set the name of the element
args new_name - a string representing the new name of the element
returns - the Element object
Get the text content of the element
returns - a string representing the content of the Element including the text() of all child Nodes
Get the Attribute called name
args name - a string representing the name of the attribute
returns - an Attribute node or null
Create a set of attributes from a hash and add them to the element
args attr - an object of {name: value} pairs
returns - the element object
Get the list of attributes attached to the element
returns - an array of Attribute objects. may be empty
Get the parent element
returns - an Element node or the Document if this is the root node
Get the document object containing the element
returns - a Document object
Get a child node by index
args idx - a zero indexed integer representing the child node to return
returns - a Node object or null
Get a list of all the immediate children of the element
returns - an array of Nodes, including text nodes
Add a child node to the node
args child - an Element node to be added as a child
returns - the element node (not the child)
Get the next sibling node
returns - a Node object or null
Get the next element sibling
returns - an Element node or null
Add a Node as a sibling immediately after this element
args siblingNode - a Node to add as a sibling
returns - the sibling object
Get the previous sibling node
returns - a Node object or null
Get the previous element sibling
returns - an Element object or null
Add a Node as a sibling immediately before this element
args siblingNode - a Node to add as a sibling
returns - the sibling object
Search the element's children by xpath
args xpath - a string representing the xpath to search
returns - an array of Node objects. may be empty
Search the element's children by xpath within the URI namespace
args xpath - a string representing the xpath to search ns_uri - a string representing the namespace URI
returns - an array of Node objects
examples
doc.find("xmlns:child-name", "ns:uri") doc.find('//y:child-name', { y: 'http://some.com/for/y'});
Return the first node node that matches the xpath expression This this is syntactic sugar for
find(xpath, ns_uri)[0]
args xpath - a string representing the xpath to search ns_uri - a string representing the namespace URI
returns - a Node or null
Search the element's children by xpath within any of the URI namespaces
args xpath - a string representing the xpath to search namespaces - a hash representing the namespaces
returns - an array of Node objects
example doc.find("ns-1:child-name", {"ns-1": "ns:uri"}) doc.find("ns-1:child1/ns-2:child2", {"ns-1": "ns:uri1", "ns-2": "ns:uri2"})
Return the first node that matches the xpath This is syntactic sugar for
find(xpath, namespaces)[0]
returns - a element object or null
Define a new namespace on the element using href for the URI. This will only define the namespace but wont add it to the node
args href - a string representing the URI of the new namespace
returns - the new Namespace object
Define a new namespace on the element using href for the URI and prefix as the prefix. This will only define the namespace but wont add it to the node
args prefix - a string representing the prefix for the new namespace href - a string representing the URI for the new namespace
returns - the new Namespace object
Get the elements's namespace
returns - a Namespace object or null
Set the element's namespace to ns
args ns - a Namespace object
returns - the element object
Add namespace with href as the URI to the element. This will search up the tree to find a namespace with the given href and, if found will use it. Otherwise it will create a new namespace.
args href - a string representing the namespace URI
returns - the namespace object
Add namespace with href as the URI and prefix as the prefix to the node. This will search up the tree to find a namespace with the given href and, if found will use it. Otherwise it will create a new namespace.
args prefix - a string representing the namespace prefix href - a string representing the namespace URI
returns - the Namespace object
Remove The element from the context
returns - the Element
Get the xpath of the element
returns - a string representing the xpath of the element