|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.excalibur.xml.xpath.XPathUtil
This is a simple XPath helper class. It uses a faster approach for simple XPath expressions and can create XPaths. If you know that your XPath expression is simple, you should use this helper instead.
Constructor Summary | |
XPathUtil()
|
Method Summary | |
static java.lang.String[] |
buildPathArray(java.lang.String xpath)
Build the input for the get...FromPath methods. |
static org.w3c.dom.Node |
getFirstNodeFromPath(org.w3c.dom.Node contextNode,
java.lang.String[] path,
boolean create)
Use a path to select the first occurence of a node. |
static org.w3c.dom.NodeList |
getNodeListFromPath(org.w3c.dom.Node contextNode,
java.lang.String[] path)
Use a path to select all occurences of a node. |
static org.w3c.dom.Node |
getSingleNode(XPathProcessor processor,
org.w3c.dom.Node rootNode,
java.lang.String path)
Return the Node from the DOM Node rootNode
using the XPath expression path . |
static boolean |
getValueAsBooleanOf(XPathProcessor processor,
org.w3c.dom.Node root,
java.lang.String path)
Get the boolean value of the node specified by the XPath. |
static boolean |
getValueAsBooleanOf(XPathProcessor processor,
org.w3c.dom.Node root,
java.lang.String path,
boolean defaultValue)
Get the boolean value of the node specified by the XPath. |
static java.lang.String |
getValueOf(XPathProcessor processor,
org.w3c.dom.Node root,
java.lang.String path)
Get the value of the node specified by the XPath. |
static java.lang.String |
getValueOf(XPathProcessor processor,
org.w3c.dom.Node root,
java.lang.String path,
java.lang.String defaultValue)
Get the value of the node specified by the XPath. |
static java.lang.String |
getValueOfNode(XPathProcessor processor,
org.w3c.dom.Node node)
Get the value of the DOM node. |
static java.lang.String |
getValueOfNode(XPathProcessor processor,
org.w3c.dom.Node node,
java.lang.String defaultValue)
Get the value of the node. |
static org.w3c.dom.NodeList |
searchNodeList(XPathProcessor processor,
org.w3c.dom.Node contextNode,
java.lang.String str)
Use an XPath string to select a nodelist. |
static org.w3c.dom.Node |
searchSingleNode(XPathProcessor processor,
org.w3c.dom.Node contextNode,
java.lang.String str)
Use an XPath string to select a single node. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public XPathUtil()
Method Detail |
public static org.w3c.dom.Node getSingleNode(XPathProcessor processor, org.w3c.dom.Node rootNode, java.lang.String path) throws XPathException
Node
from the DOM Node rootNode
using the XPath expression path
.
If the node does not exist, it is created and then returned.
This is a very simple method for creating new nodes. If the
XPath contains selectors ([,,,]) or "*" it is of course not
possible to create the new node. So if you use such XPaths
the node must exist beforehand.
An simple exception is if the expression contains attribute
tests to values (e.g. [@id = 'du' and @number = 'you'],
the attributes with the given values are added. The attributes
must be separated with 'and'.
Another problem are namespaces: XPath requires sometimes selectors for
namespaces, e.g. : /*[namespace-uri()="uri" and local-name()="name"]
Creating such a node with a namespace is not possible right now as we use
a very simple XPath parser which is not able to parse all kinds of selectors
correctly.
processor
- The XPathProcessorrootNode
- The node to start the search.path
- XPath expression for searching the node.
XPathException
- If no path is specified or the XPath engine fails.public static org.w3c.dom.Node searchSingleNode(XPathProcessor processor, org.w3c.dom.Node contextNode, java.lang.String str)
getSingleNode(XPathProcessor, Node ,String )
).
contextNode
- The node to start searching from.str
- A valid XPath string.
public static org.w3c.dom.NodeList searchNodeList(XPathProcessor processor, org.w3c.dom.Node contextNode, java.lang.String str)
contextNode
- The node to start searching from.str
- A valid XPath string.
public static java.lang.String[] buildPathArray(java.lang.String xpath)
null
is returned.
public static org.w3c.dom.Node getFirstNodeFromPath(org.w3c.dom.Node contextNode, java.lang.String[] path, boolean create)
contextNode
- The node starting the search.path
- The path to search the node. The
contextNode is searched for a child named path[0],
this node is searched for a child named path[1]...create
- If a child with the corresponding name is not found
and create is set, this node will be created.public static org.w3c.dom.NodeList getNodeListFromPath(org.w3c.dom.Node contextNode, java.lang.String[] path)
contextNode
- The node starting the search.path
- The path to search the node. The
contextNode is searched for a child named path[0],
this node is searched for a child named path[1]...public static java.lang.String getValueOf(XPathProcessor processor, org.w3c.dom.Node root, java.lang.String path) throws XPathException
null
is returned.
root
- The node to start the search.path
- XPath search expression.
null
XPathException
public static java.lang.String getValueOf(XPathProcessor processor, org.w3c.dom.Node root, java.lang.String path, java.lang.String defaultValue) throws XPathException
defaultValue
is returned.
root
- The node to start the search.path
- XPath search expression.defaultValue
- The default value if the node does not exist.
defaultValue
XPathException
public static boolean getValueAsBooleanOf(XPathProcessor processor, org.w3c.dom.Node root, java.lang.String path) throws XPathException
root
- The node to start the search.path
- XPath search expression.
XPathException
- If the node is not found.public static boolean getValueAsBooleanOf(XPathProcessor processor, org.w3c.dom.Node root, java.lang.String path, boolean defaultValue) throws XPathException
defaultValue
is returned.
root
- The node to start the search.path
- XPath search expression.defaultValue
- Default boolean value.
defaultValue
XPathException
public static java.lang.String getValueOfNode(XPathProcessor processor, org.w3c.dom.Node node)
null
is returned.
public static java.lang.String getValueOfNode(XPathProcessor processor, org.w3c.dom.Node node, java.lang.String defaultValue)
defaultValue
is
returned.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |