Class DomUtils

java.lang.Object
com.github.oowekyala.ooxml.DomUtils

public final class DomUtils extends Object
Simple utilities to work with the org.w3c.dom API.
  • Constructor Details

    • DomUtils

      public DomUtils()
  • Method Details

    • children

      public static List<Element> children(Element element)
      Returns the list of children of the given element that are also elements.
    • childrenNamed

      public static List<Element> childrenNamed(Element element, String localName)
      Returns the list of children of the given element that are also elements.
    • getAttributeOpt

      public static Optional<String> getAttributeOpt(Element element, String attributeName)
      Returns the value of the attribute with the given name as an optional.
      Parameters:
      element - Element to get the attribute from
      attributeName - Attribute name (local name, no NS)
    • asList

      public static List<Node> asList(NodeList nodeList)
      Returns an unmodifiable view of the given nodelist as a list.
      Parameters:
      nodeList - A node list
      Returns:
      A list view
    • asList

      public static List<Node> asList(NamedNodeMap nodeList)
      Returns an unmodifiable view of the given nodemap as a list. Note that as per the specification of NamedNodeMap, elements are in no particular order, but this allows to iterate over them easily.
      Parameters:
      nodeList - A node map
      Returns:
      A list view
    • toMap

      public static Map<String,Node> toMap(NamedNodeMap nodeList)
      Returns a new map of nodes built from the given node map. This uses local names to index the nodes. The returned map is modifiable.
      Parameters:
      nodeList - A node map
      Returns:
      A new, modifiable map