public final class XPATHHelper extends Object
| Modifier and Type | Method and Description |
|---|---|
static List<Attr> |
attrFilter(Collection<Node> nodes)
Extract only the Nodes which are implementations of Attr
from the given collection.
|
static List<Attr> |
attrFilter(Collection<Node> nodes,
String attributeName)
Extract only the Nodes which are implementations of Attr
from the given collection and that has a given name.
|
static List<Comment> |
commentFilter(Collection<Node> nodes)
Extract only the Nodes which are implementations of Comment
from the given collection.
|
static List<Element> |
elementFilter(Collection<Node> nodes)
Extract only the Nodes which are implementations of Element
from the given collection.
|
static Node |
getNode(Node rootNode,
String xpathString)
Gets a node matching the given XPath applied to the DOM.
|
static List<Node> |
getNodes(Node rootNode,
String xpathString)
Get a collection of nodes matching the given XPath applied to the DOM.
|
static String |
getStringValue(Node rootNode,
String xpathString)
Get the string value of the node matching the given XPath applied to
the DOM node.
|
static String |
getStringValue(Node rootNode,
String xpathString,
String defaultValue)
Get the string value of the node matching the given XPath applied
to the DOM node.
|
static List<String> |
getStringValues(Node rootNode,
String xpathString)
Get the collection of string values of the matching the given XPath
applied to the DOM rootNode.
|
static List<ProcessingInstruction> |
processingInstructionFilter(Collection<Node> nodes)
Extract only the Nodes which are implementations of ProcessingInstruction
from the given collection.
|
static List<Text> |
textFilter(Collection<Node> nodes)
Extract only the Nodes which are implementations of Text
from the given collection.
|
public static List<Node> getNodes(Node rootNode, String xpathString)
<doc>
<name first='David' last='Smith'/>
<name first='Joe' last='Jones'/>
<name first='David' last='Frost'/>
</doc>
Would return the nodes representing
<name first='David' last='Smith'/>
<name first='David' last='Frost'/>
Note that this API can also be used to retrieve Attr or Text Nodes.
If you want Elements use elementFilter()rootNode - Node we want to apply the xpath toxpathString - XPathpublic static Node getNode(Node rootNode, String xpathString)
getNodes(Node,String) and extracting the first element. If no
such node exists, null is returned.rootNode - Node we want to apply the xpath toxpathString - XPathpublic static String getStringValue(Node rootNode, String xpathString, String defaultValue)
<doc>
<name first='David' last='Smith'/>
<name first='Joe' last='Jones'/>
<name first='David' last='Frost'/>
</doc>
Would return the String 'Smith' rootNode - Node we want to apply the xpath toxpathString - XPathdefaultValue - default valuepublic static String getStringValue(Node rootNode, String xpathString)
getStringValue(rootNode, xpathString, "")rootNode - Node we want to apply the xpath toxpathString - XPathpublic static List<String> getStringValues(Node rootNode, String xpathString)
'/doc/name[@first='David']/@last'
and a rootNode pointing to the document
<doc>
<name first='David' last='Smith'/>
<name first='Joe' last='Jones'/>
<name first='David' last='Frost'/>
</doc>
Would return a collection containing 'Smith', 'Frost'rootNode - Node we want to apply the xpath toxpathString - XPathpublic static List<Attr> attrFilter(Collection<Node> nodes)
nodes - Collection of Nodespublic static List<Attr> attrFilter(Collection<Node> nodes, String attributeName)
nodes - Collection of NodesattributeName - attribute namepublic static List<Comment> commentFilter(Collection<Node> nodes)
nodes - Collection of Nodespublic static List<Element> elementFilter(Collection<Node> nodes)
nodes - Collection of Nodespublic static List<ProcessingInstruction> processingInstructionFilter(Collection<Node> nodes)
nodes - Collection of Nodespublic static List<Text> textFilter(Collection<Node> nodes)
nodes - Collection of Nodes? Copyright 2013 BMC Software, Inc.