Package org.freedesktop.dbus.utils
Class XmlUtil
- java.lang.Object
-
- org.freedesktop.dbus.utils.XmlUtil
-
public final class XmlUtil extends Object
Assorted static XML utility methods.- Author:
- hypfvieh
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static NodeListapplyXpathExpressionToDocument(String _xpathExpression, Node _xmlDocumentOrNode)Applys a xpathExpression to a xml-Document and return aNodeListwith the results.static Map<String,String>convertToAttributeMap(NamedNodeMap _nodeMap)ConvertsNamedNodeMapto aLinkedHashMap<String,String>.static List<Element>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 ElementtoElement(Node _node)
-
-
-
Method Detail
-
isElementType
public static boolean isElementType(Node _node)
Shortcut for checking if given node is of typeElement.- Parameters:
_node- node- Returns:
- true if
Element, false otherwise
-
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
public static List<Element> convertToElementList(NodeList _nodeList)
- Parameters:
_nodeList- collection of nodes- Returns:
- list of elements
-
convertToAttributeMap
public static Map<String,String> convertToAttributeMap(NamedNodeMap _nodeMap)
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
public static void printDocument(Node _docOrNode, OutputStream _outStream) throws IOException
- Parameters:
_docOrNode-DocumentorNodeobject_outStream-OutputStreamto print on- Throws:
IOException- on error
-
-