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:

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;