Package xades4j.utils
Class DOMHelper
java.lang.Object
xades4j.utils.DOMHelper
Utility methods for DOM nodes.
- Author:
- Luís
-
Method Summary
Modifier and TypeMethodDescriptionstatic Element
createElement
(Document doc, String name, String prefix, String namespaceURI) Creates an element on the given document.static Element
createElementInTempDocument
(String name, String prefix, String namespaceURI) static Collection<Element>
getChildElementsByTagNameNS
(Element e, String namespaceURI, String localName) Gets all the elements with the given qualified name that are direct children ofe
.static Element
getFirstChildElement
(Node node) Gets the first child element of a node.static Element
getFirstDescendant
(Element e, String namespaceUri, String localName) Gets the first element with the specified qualified name that is descendant ofe
.static Element
getLastChildElement
(Node node) Gets the last child element of a node.static Element
getNextSiblingElement
(Node node) Gets the next sibling of a node that is an element.static Document
getOwnerDocument
(Node node) Gets the owner document of a node.static NodeList
static void
setIdAsXmlId
(Element e, String id) Sets the "Id" attribute of an element and sets it as the element's XML ID.static void
Defines the element's "Id" attribute as its XML ID, if present.
-
Method Details
-
getOwnerDocument
Gets the owner document of a node.- Parameters:
node
- the node- Returns:
- the node's document or the node itself if it is a document node
- Throws:
NullPointerException
- ifnode
isnull
-
createElement
Creates an element on the given document. Exceptions are as inDocument.createElementNS(java.lang.String, java.lang.String)
. The qualified name is obtained byprefix
:name
if the prefix is notnull
.- Parameters:
doc
- the owner documentname
- the element's local nameprefix
- the element's prefix (may benull
)namespaceURI
- the element's uri (null
for no namespace)- Returns:
- the created element
- See Also:
-
createElementInTempDocument
-
getFirstChildElement
Gets the first child element of a node.- Parameters:
node
- the node to get the child from- Returns:
- the first element child of
node
ornull
if none - Throws:
NullPointerException
- ifnode
isnull
-
getLastChildElement
Gets the last child element of a node.- Parameters:
node
- the node to get the child from- Returns:
- the last element child of
node
ornull
if none - Throws:
NullPointerException
- ifnode
isnull
-
getNextSiblingElement
Gets the next sibling of a node that is an element.- Parameters:
node
- the node- Returns:
- the next sibling element or
null
if none - Throws:
NullPointerException
- ifnode
isnull
-
getFirstDescendant
Gets the first element with the specified qualified name that is descendant ofe
.- Parameters:
e
- the elementnamespaceUri
- namespacelocalName
- element name- Returns:
- the element or
null
if there is no such element
-
getChildElementsByTagNameNS
public static Collection<Element> getChildElementsByTagNameNS(Element e, String namespaceURI, String localName) Gets all the elements with the given qualified name that are direct children ofe
.- Parameters:
e
- the elementnamespaceURI
- namespacelocalName
- element name- Returns:
-
nodeList
-
setIdAsXmlId
Sets the "Id" attribute of an element and sets it as the element's XML ID.- Parameters:
e
- the element where the ID should be setid
- the id
-
useIdAsXmlId
Defines the element's "Id" attribute as its XML ID, if present.- Parameters:
e
- the element
-