类 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.
- 从以下版本开始:
- 3.0
- 版本:
- $$
- 作者:
- Claude Brisson
-
方法概要
修饰符和类型方法说明static 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
-
方法详细资料
-
createDocumentBuilderFactory
-
getAttribute
Extracts an attribute from a node.- 参数:
node- target nodeattr- attribute namedef- default value- 返回:
- The value of the attribute, or def
-
getAttribute
- 参数:
node- target nodeattr- attribute name- 返回:
- The value of the given attribute, or null if not present.
-
getBoolAttribute
Retrieves an attribute as a boolean.- 参数:
node- target nodeattr- attribute namedef- default value- 返回:
- True if the attribute exists and is not equal to "false" false if equal to "false", and def if not present.
-
getBoolAttribute
- 参数:
node- target nodeattr- attribute name- 返回:
- True if the attribute exists and is not equal to "false" false otherwise.
-
getIntAttribute
- 参数:
node- target nodeattr- attribute namedef- default value- 返回:
- An attribute coerced to an integer.
-
getIntAttribute
- 参数:
node- target nodeattr- attribute name- 返回:
- An attribute coerced to an integer.
-
parse
Attempts to parse the input xml into a single element.- 参数:
xml- xml stream reader- 返回:
- The document object
-
parse
Attempts to parse the input xml into a single element.- 参数:
xml- xml string- 返回:
- The document object
-
search
Search for nodes using an XPath expression- 参数:
xpath- XPath expressioncontext- evaluation context- 返回:
- org.w3c.NodeList of found nodes
- 抛出:
XPathExpressionException
-
getNodes
Search for nodes using an XPath expression- 参数:
xpath- XPath expressioncontext- evaluation context- 返回:
- List of found nodes
- 抛出:
XPathExpressionException
-
getElements
Search for elements using an XPath expression- 参数:
xpath- XPath expressioncontext- evaluation context- 返回:
- List of found elements
- 抛出:
XPathExpressionException
-
nodePath
Builds the xpath expression for a node (tries to use id/name nodes when possible to get a unique path)
- 参数:
n- target node- 返回:
- node xpath
-
nodeToString
XML Node to string- 参数:
node- XML node- 返回:
- XML node string representation
-
isXmlMimeType
Checkes whether the given mime type is an XML format- 参数:
mimeType- mime type- 返回:
trueif this mime type is an XML format
-