Class XmlElementUtil


  • public class XmlElementUtil
    extends Object
    Provides some useful methods to process the DOM.
    Author:
    Ullrich Hafner
    • Method Detail

      • getChildElementsByName

        public static List<Element> getChildElementsByName​(Element parent,
                                                           String name)
        Returns all elements in the parent that match the specified name.
        Parameters:
        parent - the parent element
        name - the expected name of the childs
        Returns:
        the elements, the list might be empty if there is no match
      • getFirstChildElementByName

        public static Optional<Element> getFirstChildElementByName​(Element parent,
                                                                   String name)
        Returns the first element in the parent that match the specified name.
        Parameters:
        parent - the parent element
        name - the expected name of the childs
        Returns:
        the first element if there is a match, Optional.empty() otherwise
      • nodeListToList

        public static List<Element> nodeListToList​(@CheckForNull
                                                   NodeList nodeList)
        Convert a NodeList into a List<Element>. Also filters out non elements from the node list.
        Parameters:
        nodeList - node list to convert.
        Returns:
        list of elements.