Package org.javalite.test
Class XPathHelper
java.lang.Object
org.javalite.test.XPathHelper
Convenience class for pulling information from XML documents. It provides a set of convenience methods for checking
 structure and content  of XML files. Such files could be XHTML generated for web apps, or any other XML.
- Author:
 - Igor Polevoy
 
- 
Constructor Summary
ConstructorsConstructorDescriptionXPathHelper(String xml)Use constructor and instance methods to only parse once and reuse a parsed tree. - 
Method Summary
Modifier and TypeMethodDescriptionattributeValue(String xpath)Returns a value of an attribute.static StringattributeValue(String xpath, String xml)Selects a value of attribute.intCounts a collection selected by XPath expression.static intCounts a collection selected by XPath expression.selectStrings(String xpath, String xml)Selects text nodes as list of stringsselectText(String xpath)Retrieves text of a single node.static StringselectText(String xpath, String xml)Selects text from a single node. 
- 
Constructor Details
- 
XPathHelper
Use constructor and instance methods to only parse once and reuse a parsed tree. Use this method in high performance applicaitons when you need to pull many values from the same document.- Parameters:
 xml- XML to parse.
 
 - 
 - 
Method Details
- 
selectText
Retrieves text of a single node.- Parameters:
 xpath- XPath pointing to a single node (not its text).- Returns:
 - text of a node.
 
 - 
attributeValue
Returns a value of an attribute.- Parameters:
 xpath- needs to point to an attribute of a single node.- Returns:
 - value of an attribute of a single node.
 
 - 
count
Counts a collection selected by XPath expression.- Parameters:
 xpath- expression which muse evaluate to a list of items.- Returns:
 - size of a collection selected by expression.
 
 - 
selectText
Selects text from a single node.- Parameters:
 xpath- expression that points to a single node.xml- document.- Returns:
 - text from a selected node.
 
 - 
count
Counts a collection selected by XPath expression.- Parameters:
 xpath- expression which mus evaluate to a list of items.xml- xml document.- Returns:
 - size of a collection selected by expression.
 
 - 
attributeValue
Selects a value of attribute.- Parameters:
 xpath- expression that points to a specific attribute of a specific node. Example:/a/b[1]/@id.xml- document.- Returns:
 - value of selected attribute.
 
 - 
selectStrings
Selects text nodes as list of strings- Parameters:
 xpath- xpath expression, should end with text() function, example: "//name/text()"xml- xml to get strings from.- Returns:
 - list of found strings matching expression, never null. If nothing matches, list will be empty.
 
 
 -