public class XPathHelper extends Object
Constructor and Description |
---|
XPathHelper(String xml)
Use constructor and instance methods to only parse once and reuse a parsed tree.
|
Modifier and Type | Method and Description |
---|---|
String |
attributeValue(String xpath)
Returns a value of an attribute.
|
static String |
attributeValue(String xpath,
String xml)
Selects a value of attribute.
|
int |
count(String xpath)
Counts a collection selected by XPath expression.
|
static int |
count(String xpath,
String xml)
Counts a collection selected by XPath expression.
|
static List<String> |
selectStrings(String xpath,
String xml)
Selects text nodes as list of strings
|
String |
selectText(String xpath)
Retrieves text of a single node.
|
static String |
selectText(String xpath,
String xml)
Selects text from a single node.
|
public XPathHelper(String xml)
xml
- XML to parse.public String selectText(String xpath)
xpath
- XPath pointing to a single node (not its text).public String attributeValue(String xpath)
xpath
- needs to point to an attribute of a single node.public int count(String xpath)
xpath
- expression which muse evaluate to a list of items.public static String selectText(String xpath, String xml)
xpath
- expression that points to a single node.xml
- document.public static int count(String xpath, String xml)
xpath
- expression which mus evaluate to a list of items.xml
- xml document.public static String attributeValue(String xpath, String xml)
xpath
- expression that points to a specific attribute of a specific node. Example: /a/b[1]/@id
.xml
- document.public static List<String> selectStrings(String xpath, String xml)
xpath
- xpath expression, should end with text() function, example: "//name/text()"xml
- xml to get strings from.Copyright © 2019 JavaLite. All rights reserved.