Package xades4j.utils

Class DOMHelper

java.lang.Object
xades4j.utils.DOMHelper

public class DOMHelper extends Object
Utility methods for DOM nodes.
Author:
Luís
  • Method Details

    • getOwnerDocument

      public static Document getOwnerDocument(Node node)
      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 - if node is null
    • createElement

      public static Element createElement(Document doc, String name, String prefix, String namespaceURI)
      Creates an element on the given document. Exceptions are as in Document.createElementNS(java.lang.String, java.lang.String). The qualified name is obtained by prefix:name if the prefix is not null.
      Parameters:
      doc - the owner document
      name - the element's local name
      prefix - the element's prefix (may be null)
      namespaceURI - the element's uri (null for no namespace)
      Returns:
      the created element
      See Also:
    • createElementInTempDocument

      public static Element createElementInTempDocument(String name, String prefix, String namespaceURI)
    • getFirstChildElement

      public static Element getFirstChildElement(Node node)
      Gets the first child element of a node.
      Parameters:
      node - the node to get the child from
      Returns:
      the first element child of node or null if none
      Throws:
      NullPointerException - if node is null
    • getLastChildElement

      public static Element getLastChildElement(Node node)
      Gets the last child element of a node.
      Parameters:
      node - the node to get the child from
      Returns:
      the last element child of node or null if none
      Throws:
      NullPointerException - if node is null
    • getNextSiblingElement

      public static Element getNextSiblingElement(Node node)
      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 - if node is null
    • getFirstDescendant

      public static Element getFirstDescendant(Element e, String namespaceUri, String localName)
      Gets the first element with the specified qualified name that is descendant of e.
      Parameters:
      e - the element
      namespaceUri - namespace
      localName - 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 of e.
      Parameters:
      e - the element
      namespaceURI - namespace
      localName - element name
      Returns:
    • nodeList

      public static NodeList nodeList(Iterable<Node> nodes)
    • setIdAsXmlId

      public static void setIdAsXmlId(Element e, String id)
      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 set
      id - the id
    • useIdAsXmlId

      public static void useIdAsXmlId(Element e)
      Defines the element's "Id" attribute as its XML ID, if present.
      Parameters:
      e - the element