java.lang.Object
com.github.hypfvieh.util.xml.XmlUtil

public final class XmlUtil extends Object
Assorted static XML utility methods.
Seit:
1.0.3 - 2018-01-10
Autor:
hypfvieh
  • Methodendetails

    • isElementType

      public static boolean isElementType(Node _node)
      Shortcut for checking if given node is of type Element.
      Parameter:
      _node - node
      Gibt zurück:
      true if Element, false otherwise
    • toElement

      public static Element toElement(Node _node)
      Checks and converts given Node to Element if possible.
      Parameter:
      _node - node
      Gibt zurück:
      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.
      Parameter:
      _xpathExpression - xpath expression
      _xmlDocumentOrNode - document or node
      Gibt zurück:
      NodeList
      Löst aus:
      IOException - on error
    • parseXmlString

      public static Document parseXmlString(String _xmlStr, boolean _validating, boolean _namespaceAware) throws IOException
      Read the given string as XML document.
      Parameter:
      _xmlStr - xml string
      _validating - boolean
      _namespaceAware - boolean
      Gibt zurück:
      Document
      Löst aus:
      IOException - on error
    • convertToElementList

      public static List<Element> convertToElementList(NodeList _nodeList)
      Convert a NodeList to a Java List of Elements.
      Parameter:
      _nodeList - collection of nodes
      Gibt zurück:
      list of elements
    • convertToAttributeMap

      public static Map<String,String> convertToAttributeMap(NamedNodeMap _nodeMap)
      Converts NamedNodeMap to a LinkedHashMap<String,String>.
      Parameter:
      _nodeMap - node map
      Gibt zurück:
      LinkedHashMap, maybe empty but never null
    • parseXmlStringWithXsdValidation

      public static Document parseXmlStringWithXsdValidation(String _xmlStr, boolean _namespaceAware, ErrorHandler _errorHandler) throws IOException
      Loads XML from string and uses referenced XSD to validate the content.
      Parameter:
      _xmlStr - string to validate
      _namespaceAware - take care of namespace
      _errorHandler - e.g. XmlErrorHandlers.XmlErrorHandlerQuiet or XmlErrorHandlers.XmlErrorHandlerRuntimeException
      Gibt zurück:
      Document
      Löst aus:
      IOException - on error
    • 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.
      Parameter:
      _xmlStr - string to validate
      _namespaceAware - take care of namespace
      Gibt zurück:
      Document
      Löst aus:
      IOException - on error
    • printDocument

      public static void printDocument(Node _docOrNode, OutputStream _outStream) throws IOException
      Dump a Document or Node-compatible object to the given OutputStream (e.g. System.out).
      Parameter:
      _docOrNode - Document or Node object
      _outStream - OutputStream to print on
      Löst aus:
      IOException - on error