Class XmlUtils
java.lang.Object
org.apache.velocity.tools.XmlUtils
Utility class for simplifying parsing of xml documents. Documents are not validated, and loading of external files (xinclude, external entities, DTDs, etc.) are disabled.
- Since:
- 3.0
- Version:
- $$
- Author:
- Claude Brisson
-
Method Summary
Modifier and TypeMethodDescriptionstatic final DocumentBuilderFactorystatic StringgetAttribute(Node node, String attr) static StringgetAttribute(Node node, String attr, String def) Extracts an attribute from a node.static booleangetBoolAttribute(Node node, String attr) static booleangetBoolAttribute(Node node, String attr, boolean def) Retrieves an attribute as a boolean.getElements(String xpath, Node context) Search for elements using an XPath expressionstatic intgetIntAttribute(Node node, String attr) static intgetIntAttribute(Node node, String attr, int def) Search for nodes using an XPath expressionstatic booleanisXmlMimeType(String mimeType) Checkes whether the given mime type is an XML formatstatic StringBuilds the xpath expression for a node (tries to use id/name nodes when possible to get a unique path)static StringnodeToString(Node node) XML Node to stringstatic ElementAttempts to parse the input xml into a single element.static ElementAttempts to parse the input xml into a single element.static NodeListSearch for nodes using an XPath expression
-
Method Details
-
createDocumentBuilderFactory
-
getAttribute
-
getAttribute
-
getBoolAttribute
Retrieves an attribute as a boolean.- Parameters:
node- target nodeattr- attribute namedef- default value- Returns:
- True if the attribute exists and is not equal to "false" false if equal to "false", and def if not present.
-
getBoolAttribute
-
getIntAttribute
-
getIntAttribute
-
parse
-
parse
-
search
Search for nodes using an XPath expression- Parameters:
xpath- XPath expressioncontext- evaluation context- Returns:
- org.w3c.NodeList of found nodes
- Throws:
XPathExpressionException
-
getNodes
Search for nodes using an XPath expression- Parameters:
xpath- XPath expressioncontext- evaluation context- Returns:
- List of found nodes
- Throws:
XPathExpressionException
-
getElements
Search for elements using an XPath expression- Parameters:
xpath- XPath expressioncontext- evaluation context- Returns:
- List of found elements
- Throws:
XPathExpressionException
-
nodePath
-
nodeToString
-
isXmlMimeType
Checkes whether the given mime type is an XML format- Parameters:
mimeType- mime type- Returns:
trueif this mime type is an XML format
-