public final class XPath extends Object implements Serializable
The subset supported by this implementation is the subset required to implement W3C XML Schema validation plus the support for absolute XPaths (W3C XMLSchema only requires supporting relative XPaths).
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other) |
static XPath |
fromString(String s,
PrefixToNamespace prefixToNS)
Equivalent to
fromString(s, prefixToNS, false) . |
static XPath |
fromString(String s,
PrefixToNamespace prefixToNS,
boolean allowDefaultNS)
Parses specified string as a XPath.
|
Path[] |
getPaths()
Returns the list of Paths composing this XPath.
|
boolean |
match(XNode xnode)
Tests if this XPath matches specified node or attribute.
|
boolean |
sameAs(XPath other)
Compares this XPath to the specified one but unlike
equals(java.lang.Object) the
order of Paths within compared XPaths is not significant. |
XNode[] |
select(Tree tree)
Returns nodes or attributes selected by this XPath in specified
subtree.
|
XNode[] |
select(Tree tree,
boolean attributePlaceholder)
Returns nodes or attributes selected by this XPath in specified
subtree.
|
String |
toString(NamespaceToPrefixes nsToPrefixes)
Returns this XPath converted to a parsable string.
|
static XNode[] |
union(XNode[] set1,
XNode[] set2)
Returns the union of specified sets.
|
public static XPath fromString(String s, PrefixToNamespace prefixToNS)
fromString(s, prefixToNS, false)
.public static XPath fromString(String s, PrefixToNamespace prefixToNS, boolean allowDefaultNS)
s
- string to be parsedprefixToNS
- map used to get namespaces corresponding to
prefixes found in string; may be null
allowDefaultNS
- when parsing an element name having no prefix,
use the default namespace if anyName.parse(java.lang.String, boolean, com.xmlmind.xml.name.PrefixToNamespace)
public Path[] getPaths()
public boolean sameAs(XPath other)
equals(java.lang.Object)
the
order of Paths within compared XPaths is not significant.public String toString(NamespaceToPrefixes nsToPrefixes)
nsToPrefixes
- map used to get prefixes corresponding to
namespaces referenced in this XPath; may be null
Name.format(boolean, com.xmlmind.xml.name.NamespaceToPrefixes)
public XNode[] select(Tree tree)
public XNode[] select(Tree tree, boolean attributePlaceholder)
tree
- subtree to be searchedattributePlaceholder
- if false
:
add an Attribute to returned array only if the XPath has successfully
selected this attribute.
if true
: when the element part of the XPath (example:
/html/body//pre in /html/body//pre/@class) has
successfully selected an Element which does not have the attribute
specified by the XPath, add anyway an Attribute with a
null
value to returned array.
Node
,
Attribute
public static XNode[] union(XNode[] set1, XNode[] set2)
set1
- an array of nodes or attributesset2
- another array of nodes or attributespublic boolean match(XNode xnode)
xnode
- node or attribute to be testedtrue
if this XPath matches specified node or
attribute; false
otherwise