Package com.xmlmind.xml.sxpath
Class XPath
- java.lang.Object
-
- com.xmlmind.xml.sxpath.XPath
-
- All Implemented Interfaces:
Serializable
public final class XPath extends Object implements Serializable
A simple implementation of XPath.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).
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)static XPathfromString(String s, PrefixToNamespace prefixToNS)Equivalent tofromString(s, prefixToNS, false).static XPathfromString(String s, PrefixToNamespace prefixToNS, boolean allowDefaultNS)Parses specified string as a XPath.Path[]getPaths()Returns the list of Paths composing this XPath.booleanmatch(XNode xnode)Tests if this XPath matches specified node or attribute.booleansameAs(XPath other)Compares this XPath to the specified one but unlikeequals(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.StringtoString(NamespaceToPrefixes nsToPrefixes)Returns this XPath converted to a parsable string.static XNode[]union(XNode[] set1, XNode[] set2)Returns the union of specified sets.
-
-
-
Method Detail
-
fromString
public static XPath fromString(String s, PrefixToNamespace prefixToNS)
Equivalent tofromString(s, prefixToNS, false).
-
fromString
public static XPath fromString(String s, PrefixToNamespace prefixToNS, boolean allowDefaultNS)
Parses specified string as a XPath. Syntax may be abbreviated or not.- Parameters:
s- string to be parsedprefixToNS- map used to get namespaces corresponding to prefixes found in string; may benullallowDefaultNS- when parsing an element name having no prefix, use the default namespace if any- Returns:
- a XPath or null if string has syntax errors or contains unknown prefixes.
- See Also:
Name.parse(java.lang.String, boolean, com.xmlmind.xml.name.PrefixToNamespace)
-
getPaths
public Path[] getPaths()
Returns the list of Paths composing this XPath. A XPath is a union of Paths (that is, Path|Path ... |Path).
-
sameAs
public boolean sameAs(XPath other)
Compares this XPath to the specified one but unlikeequals(java.lang.Object)the order of Paths within compared XPaths is not significant.
-
toString
public String toString(NamespaceToPrefixes nsToPrefixes)
Returns this XPath converted to a parsable string.- Parameters:
nsToPrefixes- map used to get prefixes corresponding to namespaces referenced in this XPath; may benull- Returns:
- this XPath converted to a parsable string
- See Also:
Name.format(boolean, com.xmlmind.xml.name.NamespaceToPrefixes)
-
select
public XNode[] select(Tree tree)
Returns nodes or attributes selected by this XPath in specified subtree.
-
select
public XNode[] select(Tree tree, boolean attributePlaceholder)
Returns nodes or attributes selected by this XPath in specified subtree.- Parameters:
tree- subtree to be searchedattributePlaceholder- iffalse: 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//prein/html/body//pre/@class) has successfully selected an Element which does not have the attribute specified by the XPath, add anyway an Attribute with anullvalue to returned array.- Returns:
- A possibly empty array of nodes or attributes selected by this XPath
- See Also:
Node,Attribute
-
union
public static XNode[] union(XNode[] set1, XNode[] set2)
Returns the union of specified sets.- Parameters:
set1- an array of nodes or attributesset2- another array of nodes or attributes- Returns:
- union of specified sets
-
match
public boolean match(XNode xnode)
Tests if this XPath matches specified node or attribute.- Parameters:
xnode- node or attribute to be tested- Returns:
trueif this XPath matches specified node or attribute;falseotherwise
-
-