java.lang.Object
com.github.hypfvieh.util.xml.XmlUtil
Assorted static XML utility methods.
- Since:
- 1.0.3 - 2018-01-10
- Author:
- hypfvieh
-
Method Summary
Modifier and TypeMethodDescriptionstatic NodeListapplyXpathExpressionToDocument(String _xpathExpression, Node _xmlDocumentOrNode) Applys a xpathExpression to a xml-Document and return aNodeListwith the results.convertToAttributeMap(NamedNodeMap _nodeMap) ConvertsNamedNodeMapto aLinkedHashMap<String,String>.convertToElementList(NodeList _nodeList) static booleanisElementType(Node _node) Shortcut for checking if given node is of typeElement.static DocumentparseXmlString(String _xmlStr, boolean _validating, boolean _namespaceAware) Read the given string as XML document.static DocumentparseXmlStringWithXsdValidation(String _xmlStr, boolean _namespaceAware) Loads XML from string and uses referenced XSD to validate the content.static DocumentparseXmlStringWithXsdValidation(String _xmlStr, boolean _namespaceAware, ErrorHandler _errorHandler) Loads XML from string and uses referenced XSD to validate the content.static voidprintDocument(Node _docOrNode, OutputStream _outStream) static Element
-
Method Details
-
isElementType
Shortcut for checking if given node is of typeElement.- Parameters:
_node- node- Returns:
- true if
Element, false otherwise
-
toElement
-
applyXpathExpressionToDocument
public static NodeList applyXpathExpressionToDocument(String _xpathExpression, Node _xmlDocumentOrNode) throws IOException Applys a xpathExpression to a xml-Document and return aNodeListwith 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
- Parameters:
_nodeList- collection of nodes- Returns:
- list of elements
-
convertToAttributeMap
ConvertsNamedNodeMapto aLinkedHashMap<String,String>.- Parameters:
_nodeMap- node map- Returns:
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.- Parameters:
_xmlStr- string to validate_namespaceAware- take care of namespace_errorHandler- e.g.XmlErrorHandlers.XmlErrorHandlerQuietorXmlErrorHandlers.XmlErrorHandlerRuntimeException- Returns:
- Document
- Throws:
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 useXmlErrorHandlers.XmlErrorHandlerQuietto suppress all errors/warnings when validating.- Parameters:
_xmlStr- string to validate_namespaceAware- take care of namespace- Returns:
- Document
- Throws:
IOException- on error
-
printDocument
- Parameters:
_docOrNode-DocumentorNodeobject_outStream-OutputStreamto print on- Throws:
IOException- on error
-