XPaths are required to be namespace-aware. Typically this is done by using
a namespace-prefixed query, with the actual namespace URI being set in the
context of the XPath expression. This is not possible to express using a
simple String return value. As a work-around, this method uses a potentially
slower, but more reliable, mechanism for ensuring the correct namespace
context is selected. The mechanism will appear like (for Elements):
.../*[local-name() = 'tag' and namespace-uri() = 'uri']
Similarly, Attributes will have a syntax similar to:
.../@*[local-name() = 'attname' and namespace-uri() = 'uri']
This mechanism makes it possible to have a simple namespace context, and a
simple String value returned from the methods on this class.
This class does not provide ways to access document-level content. Nor does it provide ways to access data relative to the Document level. Use absolute methods to access data from the Document level.
The methods on this class assume that the Document is above the top-most Element in the XML tree. The top-most Element is the one that does not have a parent Element (although it may have a parent Document). As a result, you can use Element data that is not attached to a JDOM Document.
Detached Attributes, and detached non-Element content are not treated the same. If you try to get an Absolute path to a detached Attribute or non-Element Content you will get an IllegalArgumentException. On the other hand it is legal to get the relative XPath for a detached node to itself ( but to some other node will cause an IllegalArgumentException because the nodes do not share a common ancestor).
Note
As this class has no knowledge of the document content, the generated XPath expression rely on the document structure. Hence any modification of the structure of the document may invalidate the generated XPaths.
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static String | Returns: an XPath expression to select the specified node.the Content the generated path shall select. to)Returns the absolute path to the specified to Content. |
| public static String | Returns: an XPath expression to select the specified node.the Content the generated path shall select. to)Returns the absolute path to the specified to Content. |
| private static StringBuilder | Returns: the XPath sub-expression to select the target node among its siblings.the target node for the XPath expression. node, List<?> the siblings of the target node. siblings, String the path token identifying the target node. pathToken, StringBuilder the buffer to which appending the XPath sub-expression or
buffer)null if the method shall allocate a new buffer.Appends the specified path token to the provided buffer followed by the position specification of the target node in its siblings list (if needed). |
| private static StringBuilder | Returns: an XPath expression to select the specified node.the Element the generated path shall select relative to. from, final Parent the Content the generated path shall select. to, final StringBuilder the StringBuilder to append the path to. sb)Returns the path to the specified |
| public static String | Returns: an XPath expression to select the specified node.the Content from which the the generated path shall be applied. from, final Content the Content the generated path shall select. to)Returns the relative path from the given from Content to the specified to Content as an XPath expression. |
| public static String | Returns: an XPath expression to select the specified node.the Content from which the the generated path shall be applied. from, final Attribute the Attribute the generated path shall select. to)Returns the relative path from the given from Content to the specified to Attribute as an XPath expression. |
| public static String | Returns: an XPath expression to select the specified node.the Attribute from which the the generated path shall be applied. from, final Attribute the Attribute the generated path shall select. to)Returns the relative path from the given from Attribute to the specified to Attribute as an XPath expression. |
| public static String | Returns: an XPath expression to select the specified node.the Attribute from which the the generated path shall be applied. from, final Content the Content the generated path shall select. to)Returns the relative path from the given from Attribute to the specified to Content as an XPath expression. |
| private static final StringBuilder | Returns: The same buffer as was input.The token to get the relative-to-parent XPath for nsa, final StringBuilder The buffer to append the relative stage to buffer)Calculate a single stage of an XPath query. |
| private static int |
| XPathHelper | back to summary |
|---|---|
| private XPathHelper() Private constructor. | |
| getAbsolutePath | back to summary |
|---|---|
| public static String getAbsolutePath(final Content to) Returns the absolute path to the specified to Content.
| |
| getAbsolutePath | back to summary |
|---|---|
| public static String getAbsolutePath(final Attribute to) Returns the absolute path to the specified to Content.
| |
| getPositionPath | back to summary |
|---|---|
| private static StringBuilder getPositionPath(Object node, List<?> siblings, String pathToken, StringBuilder buffer) Appends the specified path token to the provided buffer followed by the position specification of the target node in its siblings list (if needed).
| |
| getRelativeElementPath | back to summary |
|---|---|
| private static StringBuilder getRelativeElementPath(final Element from, final Parent to, final StringBuilder sb) Returns the path to the specified
| |
| getRelativePath | back to summary |
|---|---|
| public static String getRelativePath(final Content from, final Content to) Returns the relative path from the given from Content to the specified to Content as an XPath expression.
| |
| getRelativePath | back to summary |
|---|---|
| public static String getRelativePath(final Content from, final Attribute to) Returns the relative path from the given from Content to the specified to Attribute as an XPath expression.
| |
| getRelativePath | back to summary |
|---|---|
| public static String getRelativePath(final Attribute from, final Attribute to) Returns the relative path from the given from Attribute to the specified to Attribute as an XPath expression.
| |
| getRelativePath | back to summary |
|---|---|
| public static String getRelativePath(final Attribute from, final Content to) Returns the relative path from the given from Attribute to the specified to Content as an XPath expression.
| |
| getSingleStep | back to summary |
|---|---|
| private static final StringBuilder getSingleStep(final NamespaceAware nsa, final StringBuilder buffer) Calculate a single stage of an XPath query.
| |
| locate | back to summary |
|---|---|
| private static int locate(final Parent f, final List<Parent> tostack) Do an identity search in an array for a specific value. | |