HASPATH
Use the HASPATH operator to find all XML documents that contain a specified section path. You can also use this operator to do section equality testing.
Your index must be created with the PATH_SECTION_GROUP for this operator to work.
Syntax
| Syntax | Description |
|---|---|
| HASPATH(path) | Searches an XML document set and returns a score of 100 for all documents where path exists. Separate parent and child paths with the / character. For example, you can specify A/B/C. See example. |
| HASPATH(A=”value”) | Searches an XML document set and returns a score of 100 for all documents that have the element A with content value and only value. See example. |
Using Special Characters with HASPATH and INPATH
The following rules govern the use of special characters with regard to both the HASPATH and INPATH operators:
-
Left-brace ({) and right-brace (}) characters are not allowed inside
HASPATHorINPATHexpressions unless they are inside the equality operand enclosed by double quotes. So both ‘HASPATH({/A/B})’ and ‘HASPATH(/A/{B})’ will return errors. However, ‘HASPATH(/A[B="{author}"])’ will be parsed correctly. -
With exception of the backslash (\, special characters, such as dollar sign ($), percent sign (%), underscore (_), left brace ({), and right brace (}), when inside the equality operand enclosed by double or single quotes, have no special meaning. (That is, no stemming, wildcard expansion, or similar processing will be performed on them.) However, they are still subject to regular text lexing and will be translated to whitespace, with the exception of characters declared as printjoins. A backslash will still escape any character that immediately follows it.
For example, if the hyphen (-) and the double quote character (“) are defined as printjoins in a lexer preference, then:
-
The string B_TEXT inside
HASPATH(/A[B="B_TEXT")will be lexed as the phrase B TEXT. -
The string B-TEXT inside
HASPATH(/A[B="B-TEXT")will be lexed as the word B-TEXT. -
The string B’TEXT inside
HASPATH(/A[B="B'TEXT")will be lexed as the wordB”TEXT. You must use a backslash to escape the double quote between B and TEXT, or you will get a parsing error. -
The string {B_TEXT} inside
HASPATH(/A[B="{B_TEXT}")will be lexed as a phrase B TEXT.
-
Examples for HASPATH Operator
Path Testing
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.
Section Equality Testing
The query
dog INPATH A
finds
<A>dog</A>
but it also finds
<A>dog park</A>
To limit the query to the term dog and nothing else, you can use a section equality test with the HASPATH operator. For example,
HASPATH(A="dog")
finds and returns a score of 100 only for the first document, and not the second.
Limitations
Because of how XML section data is recorded, false matches might occur with XML sections that are completely empty as follows:
<A><B><C></C></B><D><E></E></D></A>
A query of HASPATH(A/B/E) or HASPATH(A/D/C) falsely matches this document. This type of false matching can be avoided by inserting text between empty tags.
False matches might also occur when the document has empty elements but has values in attributes, as in the following example document:
<Test>
<Client id="1">
<Info infoid="1"/>
</Client>
<Client id="2">
<Info infoid="2"/>
</Client>
</Test>
When searching with the following query, the query returns the document shown in the example, which is a false match.
The following query was used to return the example document, which is a false match:
SELECT main_detail_logging_id, t.xml_data.getstringval() xml_data FROM
TEST_XMLTYPE t
WHERE CONTAINS(t.xml_data,
'HASPATH(/Test/Client[@id="1"]/Info[@infoid="2"])') > 0;