Class Element
XML DOM Element Interface.
See the Element and Node interfaces.
Tables
Element.properties | Properties of the Element class, beyond the Node class |
Methods
Tables
- Element.properties
-
Properties of the Element class, beyond the Node class
Fields:
- tagName (string) the tag name for the element (readonly)
Methods
- Element:defineNamespace (namespaceURI[, prefix])
-
Creates/updates an attribute that defines a namespace (additional to DOM 2 spec).
Creates an attribute defining the specified namespace. If a defining attribute
already exists, it will be updated. It will not check if the new definition
collides with any implicitly defined namespace on the Element or on an Attribute.
Parameters:
- namespaceURI string the namespace URI to define a prefix for.
- prefix
string
The prefix to which to assign the
namespaceURI
value, orconstants.DEFAULT_NS_KEY
constant to set the default namespace. This defaults toconstants.DEFAULT_NS_KEY
if omitted. (optional)
Returns:
-
the atribute that was created/updated.
Usage:
-- defines attribute: 'xmlns:cool="http://some/namespace"' on the element local attr = elem:defineNamespace("http://some/namespace", "cool") -- defines attribute: 'xmlns="http://default/namespace"' on the element local attr = elem:defineNamespace("http://default/namespace")
- Element:getAttribute (name)
-
Gets a plain Attribute value by name, implements getAttribute.
Parameters:
Returns:
-
value of the attribute, or nil+err
- Element:getAttributeNS (namespaceURI, localName)
-
Gets a namespaced Attribute value by namespace, implements getAttributeNS.
Parameters:
- namespaceURI string Attribute namespace URI to lookup
- localName string Attribute localname to lookup
Returns:
-
value of the attribute, or nil+err
- Element:getAttributeNode (name)
-
Gets a plain Attribute node by name, implements getAttributeNode.
Parameters:
Returns:
-
the Attribute node, or nil+err
- Element:getAttributeNodeNS (namespaceURI, localName)
-
Gets a namespaced Attribute node by namespace, implements getAttributeNodeNS.
Parameters:
- namespaceURI string Attribute namespace URI to lookup
- localName string Attribute localname to lookup
Returns:
-
the Attribute node, or nil+err
- Element:getElementsByTagName (name)
-
Returns a list of children matching the name, implements getElementsByTagName.
The search is done recursively over the full depth, in a preorder traversal,
and this will be the order of the elements in the returned NodeList.
Parameters:
Returns:
-
NodeList with children with the requested name.
- Element:getElementsByTagNameNS (namespaceURI, localName)
-
Returns a list of children matching the namespace, implements getElementsByTagNameNS.
The search is done recursively over the full depth, in a preorder traversal,
and this will be the order of the elements in the returned NodeList.
Parameters:
- namespaceURI
string
Element namespace URI to search for, or
"*"
to match all. - localName
string
Element localname to search for, or
"*"
to match all.
Returns:
-
NodeList with children with the requested namespace.
- namespaceURI
string
Element namespace URI to search for, or
- Element:hasAttribute (name)
-
Checks existence of an Attribute node by name, implements hasAttribute.
Parameters:
Returns:
-
boolean
- Element:hasAttributeNS (namespaceURI, localName)
-
Checks existence of an Attribute node by namespace, implements hasAttributeNS.
Parameters:
Returns:
-
boolean
- Element:removeAttribute (name)
-
Removes a plain Attribute node by name, implements removeAttribute.
Parameters:
Returns:
true
, or nil+err - Element:removeAttributeNS (namespaceURI, localName)
-
Removes a namespaced Attribute node by namespace, implements removeAttributeNS.
Parameters:
- namespaceURI string Attribute namespace URI to remove
- localName string Attribute localname to remove
Returns:
true
, or nil+err - Element:removeAttributeNode (oldAttr)
-
Removes an Attribute node, implements removeAttributeNode.
Parameters:
Returns:
-
the removed Attribute node, or nil+err
- Element:setAttribute (name, value)
-
Creates or modifies a plain Attribute node on the Element, implements setAttribute.
If the Attribute doesn't exist yet on the Element, it will be created.
Parameters:
Returns:
-
created/updated Attribute node (this differs from the DOM2 spec)
- Element:setAttributeNS (namespaceURI, qualifiedName, value)
-
Creates or modifies a namespaced Attribute node on the Element, implements setAttributeNS.
If the Attribute doesn't exist yet on the Element, it will be created.
Parameters:
- namespaceURI string the namespaceURI for the Attribute.
- qualifiedName string the qualified attribute name.
- value string attribute value.
Returns:
-
created/updated Attribute node (this differs from the DOM2 spec)
- Element:setAttributeNode (newAttr)
-
Adds or replaces a plain Attribute node on the Element, implements setAttributeNode.
If an Attribute by this name already exists on the Element, it will be replaced.
Parameters:
Returns:
true
or the replaced Attribute node, or nil+err - Element:setAttributeNodeNS (newAttr)
-
Adds or replaces a namespaced Attribute node on the Element, implements setAttributeNodeNS.
If an Attribute by this name already exists on the Element, it will be replaced.
Parameters:
Returns:
true
or the replaced Attribute node, or nil+err - Element:write (buffer, namespacesInScope)
-
exports the XML (additional to DOM 2 spec).
Writing namespaces:
Namespaces set in the
namespacesInScope
table will be assumed to have already been defined and no declarations for those will be generated.Namespaces in use in this Element or any of its Attributes will implicitly be defined on the Element unless they are already in scope.
Namespaces set as attributes on this element will be defined on this Element. This allows to define a namespace on a higher level element (where it is not necessarily in use), to prevent many duplicate definitions further down the tree. See Element:defineNamespace.
Parameters:
- buffer array an array to which the chunks can be added.
- namespacesInScope
table
list of namespace URIs indexed by prefix
(or
constants.DEFAULT_NS_KEY
for the default namespace).
Returns:
-
the buffer array