Package com.avoka.fc.core.util
Class XPath
- java.lang.Object
-
- com.avoka.fc.core.util.XPath
-
public class XPath extends Object
Provides an XPath implementation that "flips" the standard way of doing Jaxen around - it allows you to define the element once, and then evaluate multiple xpath expressions against that node.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getPathValue(String path)
Return the trimmed string value for the given path.List
selectNodes(String xpath)
Select multiple nodes using the given XPathElement
selectSingleNode(String xpath)
Select a single node using the given XPathvoid
setNodeValue(String path, Boolean value)
Set a node to a specified boolean valuevoid
setNodeValue(String path, Number value)
Set a node to a specified numeric valuevoid
setNodeValue(String path, String value)
Set a node to a specified valuevoid
setNodeValue(String path, String value, boolean optional)
Set a node to a specified valueString
stringValueOf(String xpath)
Return the string value for the given path.
-
-
-
Constructor Detail
-
XPath
public XPath(Document document)
Create an XPath object based on the given document- Parameters:
document
- a non-null XML document
-
XPath
public XPath(Element documentElement)
Create an XPath object based on the given element- Parameters:
documentElement
- a non-null XML document element
-
-
Method Detail
-
selectSingleNode
public Element selectSingleNode(String xpath) throws ApplicationException
Select a single node using the given XPath- Parameters:
xpath
- the input XPath- Returns:
- the element selected by the XPath
- Throws:
ApplicationException
- if there was an error evaluating the XPath
-
selectNodes
public List selectNodes(String xpath) throws ApplicationException
Select multiple nodes using the given XPath- Parameters:
xpath
- the input XPath- Returns:
- the list of elements selected by the XPath
- Throws:
ApplicationException
- if there was an error evaluating the XPath
-
stringValueOf
public String stringValueOf(String xpath)
Return the string value for the given path.- Parameters:
xpath
- the input XPath- Returns:
- the string value
-
getPathValue
public String getPathValue(String path)
Return the trimmed string value for the given path.- Parameters:
path
- the input XPath- Returns:
- the trimmed string value
-
setNodeValue
public void setNodeValue(String path, String value)
Set a node to a specified value- Parameters:
path
- the XPath of an existing nodevalue
- the new value
-
setNodeValue
public void setNodeValue(String path, Boolean value)
Set a node to a specified boolean value- Parameters:
path
- the XPath of an existing nodevalue
- the new value
-
setNodeValue
public void setNodeValue(String path, Number value)
Set a node to a specified numeric value- Parameters:
path
- the XPath of an existing nodevalue
- the new value
-
setNodeValue
public void setNodeValue(String path, String value, boolean optional)
Set a node to a specified value- Parameters:
path
- the XPath of an existing nodevalue
- the new valueoptional
- Determines the behaviour if the node does not exist. If true, this will be silently ignored and nothing will be done; otherwise anApplicationException
will be thrown.
-
-