INPATH
Use the INPATH operator to do path searching in XML documents. This operator is like the WITHIN operator except that the right-hand side is a parentheses enclosed path, rather than a single section name.
Your index must be created with the PATH_SECTION_GROUP for the INPATH operator to work.
Syntax
The INPATH operator has the following syntax:
Top-Level Tag Searching
| Syntax | Description |
|---|---|
term INPATH (/A) term INPATH (A) |
Returns documents that have term within the and tags. |
Any-Level Tag Searching
| Syntax | Description |
|---|---|
| term INPATH (//A) | Returns documents that have term in the tag at any level. This query is the same as ‘term WITHIN A’ |
Direct Parentage Path Searching
| Syntax | Description |
|---|---|
| term INPATH (A/B) | Returns documents where term appears in a B element which is a direct child of a top-level A element. For example, a document containing is returned. |
Single-Level Wildcard Searching
| Syntax | Description |
|---|---|
| term INPATH (A/*/B) | Returns documents where term appears in a B element which is a grandchild (two levels down) of a top-level A element. For example a document containing is returned. |
Multi-level Wildcard Searching
| Syntax | Description |
|---|---|
| term INPATH (A//B//*/C) | Returns documents where term appears in a C element which is 3 levels down from a B element which is two levels down (grandchild) of a top-level A element. |
Any-Level Descendant Searching
| Syntax | Description |
|---|---|
| term INPATH(A//B) | Returns documents where term appears in a B element which is some descendant (any level) of a top-level A element. |
Attribute Searching
| Syntax | Description |
|---|---|
| term INPATH (//A/@B) | Returns documents where term appears in the B attribute of an A element at any level. Attributes must be bound to a direct parent. |
Descendant/Attribute Existence Testing
| Syntax | Description |
|---|---|
| term INPATH (A[B]) | Returns documents where term appears in a top-level A element which has a B element as a direct child. |
| term INPATH (A[.//B]) | Returns documents where term appears in a top-level A element which has a B element as a descendant at any level. |
| term INPATH (//A[@B]) | Finds documents where term appears in an A element at any level which has a B attribute. Attributes must be tied to a direct parent. |
Attribute Value Testing
| Syntax | Description |
|---|---|
| term INPATH (A[@B = “value”]) | Finds all documents where term appears in a top-level A element which has a B attribute whose value is value. |
| term INPATH (A[@B != “value”]) | Finds all documents where term appears in a top-level A element which has a B attribute whose value is not value. |
Tag Value Testing
| Syntax | Description |
|---|---|
| term INPATH (A[B = “value”])) | Returns documents where term appears in an A tag which has a B tag whose value is value. |
NOT Testing
| Syntax | Description |
|---|---|
| term INPATH (A[NOT(B)]) | Finds documents where term appears in a top-level A element which does not have a B element as an immediate child. |
AND and OR Testing
| Syntax | Description |
|---|---|
| term INPATH (A[B and C]) | Finds documents where term appears in a top-level A element which has a B and a C element as an immediate child. |
term INPATH (A[B and @C="value"]]) |
Finds documents where term appears in a top-level A element which has a B element and a C attribute whose value is value. |
| term INPATH (A [B OR C]) | Finds documents where term appears in a top-level A element which has a B element or a C element. |
Combining Path and Node Tests
| Syntax | Description |
|---|---|
| term INPATH (A[@B = “value”]/C/D) | Returns documents where term appears in aD element which is the child of a C element, which is the child of a top-level A element with a B attribute whose value is value. |
Nested INPATH
Nest the entire INPATH expression in another INPATH expression as follows:
(dog INPATH (//A/B/C)) INPATH (D)
When you do so, the two INPATH paths are completely independent. The outer INPATH path does not change the context node of the inner INPATH path. For example:
(dog INPATH (A)) INPATH (D)
never finds any documents, because the inner INPATH is looking for dog within the top-level tag A, and the outer INPATH constrains that to document with top-level tag D. A document can have only one top-level tag, so this expression never finds any documents.
Case-Sensitivity
Tags and attribute names in path searching are case-sensitive. That is,
dog INPATH (A)
finds <A>dog</A> but does not find <a>dog</a>. Instead use
dog INPATH (a)
Using Special Characters with INPATH
See “Using Special Characters with HASPATH and INPATH” for information on using special characters, such as the percent sign (%) or the backslash (), with INPATH.
Examples for INPATH Operator
Top-Level Tag Searching
To find all documents that contain the term dog in the top-level tag <A>:
dog INPATH (/A)
or
dog INPATH(A)
Any-Level Tag Searching
To find all documents that contain the term dog in the <A> tag at any level:
dog INPATH(//A)
This query finds the following documents:
<A>dog</A>
and
<C><B><A>dog</A></B></C>
Direct Parentage Searching
To find all documents that contain the term dog in a B element that is a direct child of a top-level A element:
dog INPATH(A/B)
This query finds the following XML document:
<A><B>My dog is friendly.</B><A>
but does not find:
<C><B>My dog is friendly.</B></C>
Tag Value Testing
You can test the value of tags. For example, the query:
dog INPATH(A[B="dog"])
Finds the following document:
<A><B>dog</B></A>
But does not find:
<A><B>My dog is friendly.</B></A>
Attribute Searching
You can search the content of attributes. For example, the query:
dog INPATH(//A/@B)
Finds the document
<C><A B="snoop dog"> </A> </C>
Attribute Value Testing
You can test the value of attributes. For example, the query
California INPATH (//A[@B = "home address"])
Finds the document:
<A B="home address">San Francisco, California, USA</A>
But does not find:
<A B="work address">San Francisco, California, USA</A>
Path Testing
You can test if a path exists with the HASPATH operator. For example, the query:
HASPATH(A/B/C)
finds and returns a score of 100 for the document
<A><B><C>dog</C></B></A>
without the query having to reference dog at all.
Limitations
Testing for Equality
The following is an example of an INPATH equality test.
dog INPATH (A[@B = "foo"])
The following limitations apply for these expressions:
-
Only equality and inequality are supported. Range operators and functions are not supported.
-
The left hand side of the equality must be an attribute. Tags and literals here are not enabled.
-
The right hand side of the equality must be a literal. Tags and attributes here are not allowed.
-
The test for equality depends on your lexer settings. With the default settings, the query
dog INPATH (A[@B= "pot of gold"])
matches the following sections:
<A B="POT OF GOLD">dog</A>
and
<A B="pot of gold">dog</A>
because lexer is case-insensitive by default.
<A B="POT IS GOLD">dog</A>
because of and is are default stopwords in English, and a stopword matches any stopword word.
<A B="POT_OF_GOLD">dog</A>
because the underscore character is not a join character by default.