Class XmlUtil


  • public final class XmlUtil
    extends Object
    Assorted static XML utility methods.
    Author:
    hypfvieh
    • Method Detail

      • isElementType

        public static boolean isElementType​(Node _node)
        Shortcut for checking if given node is of type Element.
        Parameters:
        _node - node
        Returns:
        true if Element, false otherwise
      • toElement

        public static Element toElement​(Node _node)
        Checks and converts given Node to Element if possible.
        Parameters:
        _node - node
        Returns:
        Element or null if given Node is not Element subtype
      • applyXpathExpressionToDocument

        public static NodeList applyXpathExpressionToDocument​(String _xpathExpression,
                                                              Node _xmlDocumentOrNode)
                                                       throws IOException
        Applys a xpathExpression to a xml-Document and return a NodeList with the results.
        Parameters:
        _xpathExpression - xpath expression
        _xmlDocumentOrNode - document or node
        Returns:
        NodeList
        Throws:
        IOException - on error
      • parseXmlString

        public static Document parseXmlString​(String _xmlStr,
                                              boolean _validating,
                                              boolean _namespaceAware)
                                       throws IOException
        Read the given string as XML document.
        Parameters:
        _xmlStr - xml string
        _validating - boolean
        _namespaceAware - boolean
        Returns:
        Document
        Throws:
        IOException - on error
      • convertToElementList

        public static List<Element> convertToElementList​(NodeList _nodeList)
        Convert a NodeList to a Java List of Elements.
        Parameters:
        _nodeList - collection of nodes
        Returns:
        list of elements
      • parseXmlStringWithXsdValidation

        public static Document parseXmlStringWithXsdValidation​(String _xmlStr,
                                                               boolean _namespaceAware)
                                                        throws IOException
        Loads XML from string and uses referenced XSD to validate the content. This method will use XmlErrorHandlers.XmlErrorHandlerQuiet to suppress all errors/warnings when validating.
        Parameters:
        _xmlStr - string to validate
        _namespaceAware - take care of namespace
        Returns:
        Document
        Throws:
        IOException - on error