Class DomUtils


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

      Constructors 
      Constructor Description
      DomUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<org.w3c.dom.Node> asList​(org.w3c.dom.NamedNodeMap nodeList)
      Returns an unmodifiable view of the given nodemap as a list.
      static java.util.List<org.w3c.dom.Node> asList​(org.w3c.dom.NodeList nodeList)
      Returns an unmodifiable view of the given nodelist as a list.
      static java.util.List<org.w3c.dom.Element> children​(org.w3c.dom.Element element)
      Returns the list of children of the given element that are also elements.
      static java.util.List<org.w3c.dom.Element> childrenNamed​(org.w3c.dom.Element element, java.lang.String localName)
      Returns the list of children of the given element that are also elements.
      static java.util.Optional<java.lang.String> getAttributeOpt​(org.w3c.dom.Element element, java.lang.String attributeName)
      Returns the value of the attribute with the given name as an optional.
      static java.util.Map<java.lang.String,​org.w3c.dom.Node> toMap​(org.w3c.dom.NamedNodeMap nodeList)
      Returns a new map of nodes built from the given node map.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DomUtils

        public DomUtils()
    • Method Detail

      • children

        public static java.util.List<org.w3c.dom.Element> children​(org.w3c.dom.Element element)
        Returns the list of children of the given element that are also elements.
      • childrenNamed

        public static java.util.List<org.w3c.dom.Element> childrenNamed​(org.w3c.dom.Element element,
                                                                        java.lang.String localName)
        Returns the list of children of the given element that are also elements.
      • getAttributeOpt

        public static java.util.Optional<java.lang.String> getAttributeOpt​(org.w3c.dom.Element element,
                                                                           java.lang.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 java.util.List<org.w3c.dom.Node> asList​(org.w3c.dom.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 java.util.List<org.w3c.dom.Node> asList​(org.w3c.dom.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 java.util.Map<java.lang.String,​org.w3c.dom.Node> toMap​(org.w3c.dom.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