Enum XmlUtil

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<XmlUtil>

    public enum XmlUtil
    extends java.lang.Enum<XmlUtil>
    A collection of utility methods for xml handling.
    Author:
    Jan Ortmann
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Optional<org.w3c.dom.Element> findFirstElement​(org.w3c.dom.Node parent)
      Returns the first Element node
      static java.util.Optional<org.w3c.dom.Element> findFirstElement​(org.w3c.dom.Node parent, java.lang.String tagName)  
      static java.lang.String getCDATAorTextContent​(org.w3c.dom.Node node)
      Returns the node's first CDATA section if the node has one.
      static org.w3c.dom.Element getElement​(org.w3c.dom.Node parent, java.lang.String tagName, int index)
      Returns the child element with the given tag name and index.
      static java.util.List<org.w3c.dom.Element> getElements​(org.w3c.dom.Node parent, java.lang.String tagName)
      Returns all child elements with the given tag name.
      static java.util.List<org.w3c.dom.Element> getElementsFromNode​(org.w3c.dom.Element elem, java.lang.String nodeName, java.lang.String attributeName, java.lang.String attributeValue)
      Returns a list of element's with the following criteria: the node name must be equal to the given node name the node must contain an attribute with the attribute name the value of the attribute (with the given name) must be equal to the given value
      static org.w3c.dom.CDATASection getFirstCDataSection​(org.w3c.dom.Node node)
      Returns the node's first CDATA section or null if the node hasn't got one.
      static org.w3c.dom.Element getFirstElement​(org.w3c.dom.Node parent)
      Returns the first Element node
      static org.w3c.dom.Element getFirstElement​(org.w3c.dom.Node parent, java.lang.String tagName)  
      static org.w3c.dom.Text getTextNode​(org.w3c.dom.Node node)
      Returns the node's text child node or null if the node hasn't got a text node.
      static java.lang.String getValueFromNode​(org.w3c.dom.Element elem, java.lang.String nodeName)
      Returns the value of the first element with the given node name, starts searching by the given Element
      static XmlUtil valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static XmlUtil[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • values

        public static XmlUtil[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (XmlUtil c : XmlUtil.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static XmlUtil valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • findFirstElement

        public static final java.util.Optional<org.w3c.dom.Element> findFirstElement​(org.w3c.dom.Node parent,
                                                                                     java.lang.String tagName)
      • findFirstElement

        public static final java.util.Optional<org.w3c.dom.Element> findFirstElement​(org.w3c.dom.Node parent)
        Returns the first Element node
      • getElement

        public static final org.w3c.dom.Element getElement​(org.w3c.dom.Node parent,
                                                           java.lang.String tagName,
                                                           int index)
        Returns the child element with the given tag name and index. The index is the position of the element considering all child elements with the given tag name.
        Parameters:
        parent - The parent node.
        tagName - the element tag name.
        index - The 0 based position of the child.
        Returns:
        The element at the specified index
        Throws:
        java.lang.IndexOutOfBoundsException - if no element exists at the specified index.
      • getElements

        public static final java.util.List<org.w3c.dom.Element> getElements​(org.w3c.dom.Node parent,
                                                                            java.lang.String tagName)
        Returns all child elements with the given tag name. Considers only direct children. Use Element.getElementsByTagName(String) to search all descendants.
        Parameters:
        parent - The parent node.
        tagName - the element tag name.
        Returns:
        all child elements with the matching tag name
      • getTextNode

        public static final org.w3c.dom.Text getTextNode​(org.w3c.dom.Node node)
        Returns the node's text child node or null if the node hasn't got a text node.
      • getFirstCDataSection

        public static final org.w3c.dom.CDATASection getFirstCDataSection​(org.w3c.dom.Node node)
        Returns the node's first CDATA section or null if the node hasn't got one.
      • getCDATAorTextContent

        public static final java.lang.String getCDATAorTextContent​(org.w3c.dom.Node node)
        Returns the node's first CDATA section if the node has one. If not, this returns the node's text child node or null if the node hasn't got a text node.
      • getValueFromNode

        public static final java.lang.String getValueFromNode​(org.w3c.dom.Element elem,
                                                              java.lang.String nodeName)
        Returns the value of the first element with the given node name, starts searching by the given Element
        Parameters:
        elem - The first element (root or parent) element the search begins
        nodeName - The name searching for
      • getElementsFromNode

        public static final java.util.List<org.w3c.dom.Element> getElementsFromNode​(org.w3c.dom.Element elem,
                                                                                    java.lang.String nodeName,
                                                                                    java.lang.String attributeName,
                                                                                    java.lang.String attributeValue)
        Returns a list of element's with the following criteria:
        • the node name must be equal to the given node name
        • the node must contain an attribute with the attribute name
        • the value of the attribute (with the given name) must be equal to the given value