6.6.1 XPath over Document View

When an XPath query is executed, the XPath expression specified is applied to the document view of the workspace being searched.

For example, consider a workspace with the following structure (based on the earlier example in Section 6.4.1.1, with the addition of a top-most root node):


<?xml version="1.0" encoding="UTF-8"?>
<jcr:root xmlns:jcr="http://www.jcp.org/jcr/1.0"
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:myapp="http://mycorp.com/myapp"
xmlns:mynt="http://mycorp.com/mynt"
jcr:primaryType="nt:unstructured">
<myapp:document jcr:primaryType="mynt:document">
myapp:title="JSR 170"
myapp:lead="Content Repository">
<myapp:body jcr:primaryType="mynt:body">
<myapp:paragraph jcr:primaryType="mynt:paragraph"
myapp:title="Node Types"
myapp:text="An important feature..."/>
</myapp:body>
</myapp:document>
</jcr:root>


Note that in the above, the XML has been formatted for readability. The actual XML stream might not have any extraneous whitespace between elements or attributes.

In this case, to find the node called myapp:paragraph, the following XPath expression would be used:

//element(*, mynt:paragraph)[@myapp:title="Node Types"]

This query will return the node at the repository workspace path (as opposed to an XPath):

/myapp:document/myapp:body/myapp:paragraph