JCR Explorer and XPath

 

+

Search Tips   |   Advanced Search

 

Sample XPath Queries

If when syndicating from portal1 to portal2, you get error messages in SystemOut.log similar to...

Could not save item with id DepRef(id:127e0f804d814af39094dbb569f96be1 type: com.aptrix.pluto.site.SiteArea nonDraft:true draft:false purged:false parentId:edad42004d81483d9076dbb569f96be1 timeStamp:1238016447593 stateUpdate: false versions:null moved: false) because it could not find its parent.

You can run an XPath query in JCR Explorer in both portals similar to...

//element(*, ibmcontentwcm:siteArea)[@jcr:uuid = '127e0f804d814af39094dbb569f96be1']

If the site area exists in both the syndicator and subscriber portals, but the query only shows the site area existing in syndicator portal, that means uuid on subscriber is incorrect. To fix...

  1. Delete site area on subscriber
  2. Edit site area on syndicator and then save, to give item a fresh time stamp.
  3. Re-syndicate

If you get error...

Could not resolve a reference from item of type com.aptrix.pluto.cmpnt.MenuCmpnt and name featured profession for landing to an item with id {08da99004d92f6a28e23dfb569f96be1, com.aptrix.pluto.taxonomy.Category}. The reference is of type com.aptrix.deployment.subscriber.SyndicationReferenceResolver$MenuCmpntHandler$CategoryReference.

You can run an XPath query in JCR Explorer in both portals similar to...

//element(*, ibmcontentwcm:webCategory)[@jcr:uuid = '08da99004d92f6a28e23dfb569f96be1']

Again, if item exists on both syndicator and subscriber, but query only shows existence on syndicator, that means uuid on subscriber if invalid. You can delete on subscriber, save with fresh time stamp on syndicator, and then rerun syndication.

Other JCR query examples:

//element(*, ibmcontentwcm:webFolder)[@jcr:uuid = 'b719e3004fd327d489ef8bc0a4677a32']

/element(ibmcontentwcm:items, ibmcontentwcm:draftSummary)[@ibmcontentwcm:stageUUID = '62a03800400db03a8b4cebc479de5989' and @ibmcontentwcm:draftClassification = 'Content']

//element(*, icm:documentLibrary)[@jcr:uuid = 'f23393004113e46c96dcde3a76649ae4']

//(element(*, ibmcontentwcm:draftSummary) | element(*, ibmcontentwcm:webContent))[@ibmcontentwcm:workflowStageRef = '7b9a20804125388ca40cbfa5924c7af2']

 

JCR DB Repository Types

 ibmcontentwcm:alternateDesignElement  ibmcontentwcm:alternateLinkElement  ibmcontentwcm:attributeReferenceElement  ibmcontentwcm:authoringTemplate  ibmcontentwcm:authoringTemplate_v  ibmcontentwcm:basePathElement  ibmcontentwcm:baseReferenceElement  ibmcontentwcm:classificationData  ibmcontentwcm:configParamElement  ibmcontentwcm:customAction  ibmcontentwcm:customAction_v  ibmcontentwcm:dateElement  ibmcontentwcm:deletionSummary  ibmcontentwcm:deletionSummary_v  ibmcontentwcm:documentManagerElement  ibmcontentwcm:documentManagerReferenceElement  ibmcontentwcm:draftSummary  ibmcontentwcm:draftSummary_v  ibmcontentwcm:elementReference  ibmcontentwcm:emailAction  ibmcontentwcm:emailAction_v  ibmcontentwcm:expireAction  ibmcontentwcm:expireAction_v  ibmcontentwcm:federatedContentElement  ibmcontentwcm:federatedReferenceElement  ibmcontentwcm:filenetContentElement  ibmcontentwcm:filenetContentReferenceElement  ibmcontentwcm:historyLogEntry  ibmcontentwcm:htmlElement  ibmcontentwcm:imageElement  ibmcontentwcm:indentElement  ibmcontentwcm:indexElement  ibmcontentwcm:inlineEditElement  ibmcontentwcm:jspIncludeElement  ibmcontentwcm:linkElement  ibmcontentwcm:localeNavigationElement  ibmcontentwcm:localizationSettings  ibmcontentwcm:localizationSettings_v  ibmcontentwcm:localizeDraftAction  ibmcontentwcm:localizeDraftAction_v  ibmcontentwcm:menuElement  ibmcontentwcm:metaDataElement  ibmcontentwcm:navigatorElement  ibmcontentwcm:numericElement  ibmcontentwcm:optionSelectionElement  ibmcontentwcm:pageInfoElement  ibmcontentwcm:pagingElement  ibmcontentwcm:pathElement  ibmcontentwcm:permissionEntry  ibmcontentwcm:personalizationElement  ibmcontentwcm:placeholderElement  ibmcontentwcm:positionData  ibmcontentwcm:presentationTemplate  ibmcontentwcm:presentationTemplate_v  ibmcontentwcm:publishAction  ibmcontentwcm:publishAction_v  ibmcontentwcm:publishStage  ibmcontentwcm:publishStage_v  ibmcontentwcm:referenceElement  ibmcontentwcm:resourceElement  ibmcontentwcm:richTextElement  ibmcontentwcm:scheduledMoveAction  ibmcontentwcm:scheduledMoveAction_v  ibmcontentwcm:searchElement  ibmcontentwcm:servletPathElement  ibmcontentwcm:shortTextElement 
 ibmcontentwcm:siteArea 
    Parent types 
        ibmcontentwcm:positionData 
        ibmcontentwcm:webComponent 
        nt:base 
 ibmcontentwcm:siteArea_v  ibmcontentwcm:siteNavigatorElement  ibmcontentwcm:stylesheetElement  ibmcontentwcm:stylesheetElementReference  ibmcontentwcm:subscriberComponent  ibmcontentwcm:subscriberComponent_v  ibmcontentwcm:syndicatorComponent  ibmcontentwcm:syndicatorComponent_v  ibmcontentwcm:tagData  ibmcontentwcm:taxonomyElement  ibmcontentwcm:textElement  ibmcontentwcm:textSelectionElement  ibmcontentwcm:userSelectionElement  ibmcontentwcm:usernameElement  ibmcontentwcm:webCategory  ibmcontentwcm:webCategory_v  ibmcontentwcm:webComponent  ibmcontentwcm:webComponent_v  ibmcontentwcm:webContent  ibmcontentwcm:webContentLink  ibmcontentwcm:webContentLink_v  ibmcontentwcm:webContent_v  ibmcontentwcm:webElement  ibmcontentwcm:webFolder  ibmcontentwcm:webFolder_v  ibmcontentwcm:workflow  ibmcontentwcm:workflowAction  ibmcontentwcm:workflowActionEntry  ibmcontentwcm:workflowAction_v  ibmcontentwcm:workflowPermission  ibmcontentwcm:workflowStage  ibmcontentwcm:workflowStage_v  ibmcontentwcm:workflow_v  ibmpersonalization:applicationObject  ibmpersonalization:applicationObject_v  ibmpersonalization:campaign  ibmpersonalization:campaign_v  ibmpersonalization:contentSpot  ibmpersonalization:contentSpot_v  ibmpersonalization:dynamicAttribute  ibmpersonalization:previewProfile  ibmpersonalization:previewProfile_v  ibmpersonalization:publishTarget  ibmpersonalization:publishTarget_v  ibmpersonalization:publishable  ibmpersonalization:resourceCollection  ibmpersonalization:resourceCollection_v  ibmpersonalization:rule  ibmpersonalization:ruleEvent  ibmpersonalization:ruleEvent_v  ibmpersonalization:ruleSpotMapping  ibmpersonalization:ruleSpotMapping_v  ibmpersonalization:rule_v  icm:LifeCycle  icm:LifeCycleState  icm:WorkflowItem  icm:WorkflowProcessDefinition  icm:auditData  icm:auditPruningStatus  icm:base  icm:baseEvent  icm:binaryElement  icm:category  icm:categoryData  icm:category_v  icm:collection  icm:collection_v  icm:component  icm:component_v  icm:compositeComponent  icm:compositeComponent_v  icm:compositeElement  icm:content  icm:contentRoot  icm:controlData  icm:descriptionData  icm:document  icm:documentLibrary  icm:documentLibrary_v  icm:document_v  icm:dynamicCollection  icm:dynamicCollection_v  icm:element  icm:eventListener  icm:folder  icm:folder_v  icm:item  icm:item_v  icm:jcrEvent  icm:managedData  icm:metadata  icm:namedData  icm:peopleData  icm:publishData  icm:query  icm:query_v  icm:rootNodeT_v  icm:rootNodeType  icm:standardData  icm:textsearch  lotus:collaborativeDocument  lotus:collaborativeDocument_v  lotus:draft  lotus:draft_v  lotus:rendition  lotus:rendition_v  lotus:searchTemplate  lotus:searchTemplate_v  nt:JCRActivity  nt:JCRAssignment  nt:JCRInternals  nt:JCRInternalsRoot  nt:JCRProcess  nt:base  nt:content  nt:content_v  nt:default  nt:file  nt:folder  nt:hierarchyItem  nt:hierarchyNode  nt:internalVerNT  nt:query  nt:query_v  nt:referenceable  nt:verBrCtrl  nt:verBrCtrl_v  nt:version  nt:versionContainer  nt:versionabl_v  nt:versionable  nt:versionedChild  nt:versionedNode  pvsnode:policyRoot  pvsnode:policyRoot_v  pvsnode:pvsNode2  pvsnode:pvsNode2_v  remote:stagingContainer 

 

Prefixes

 

Nodes

In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node).

Look at the following XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

    <book>
      <title lang="en">Harry Potter</title>
      <author>J K. Rowling</author>
      <year>2005</year>
      <price>29.99</price>
    </book>

</bookstore> 

Example of nodes in the XML document above:

<bookstore> document node
<author>J K. Rowling</author> element node
lang="en" attribute node

 

Atomic values

Atomic values are nodes with no children or parent.

Example of atomic values:

 J K. Rowling

"en" 

 

Items

Items are atomic values or nodes.

 

Parent

Each element and attribute has one parent. In the following example; the book element is the parent of the title, author, year, and price:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book> 

 

Children

Element nodes may have zero, one or more children.

In the following example; the title, author, year, and price elements are all children of the book element:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book> 

 

Siblings

Nodes that have the same parent.

In the following example; the title, author, year, and price elements are all siblings:

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book> 

 

Ancestors

A node's parent, parent's parent, etc.

In the following example; the ancestors of the title element are the book element and the bookstore element:

<bookstore>

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

</bookstore> 

 

Descendants

A node's children, children's children, etc.

In the following example; descendants of the bookstore element are the book, title, author, year, and price elements:

<bookstore>

<book>
  <title>Harry Potter</title>
  <author>J K. Rowling</author>
  <year>2005</year>
  <price>29.99</price>
</book>

</bookstore> 

 

Selecting Nodes

XPath uses path expressions to select nodes in an XML document. The node is selected by following a path or steps. The most useful path expressions are listed below:

Expression Description
nodename Selects all child nodes of the named node
/ Selects from the root node
// Selects nodes in the document from the current node that match the selection no matter where they are
. Selects the current node
.. Selects the parent of the current node
@ Selects attributes

In the table below we have listed some path expressions and the result of the expressions:

Path Expression Result
bookstore Selects all the child nodes of the bookstore element
/bookstore Selects the root element bookstore

If the path starts with a slash ( / ) it always represents an absolute path to an element!

bookstore/book Selects all book elements that are children of bookstore
//book Selects all book elements no matter where they are in the document
bookstore//book Selects all book elements that are descendant of the bookstore element, no matter where they are under the bookstore element
//@lang Selects all attributes that are named lang

 

Predicates

Predicates are used to find a specific node or a node that contains a specific value. Predicates are always embedded in square brackets.

In the table below we have listed some path expressions with predicates and the result of the expressions:

Path Expression Result
/bookstore/book[1] Selects the first book element that is the child of the bookstore element.

IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!

/bookstore/book[last()] Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1] Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3] Selects the first two book elements that are children of the bookstore element
//title[@lang] Selects all the title elements that have an attribute named lang
//title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng'
/bookstore/book[price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00
/bookstore/book[price>35.00]/title Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00

 

Selecting Unknown Nodes

XPath wildcards can be used to select unknown XML elements.

Wildcard Description
* Matches any element node
@* Matches any attribute node
node() Matches any node of any kind

In the table below we have listed some path expressions and the result of the expressions:

/bookstore/* Selects all the child nodes of the bookstore element
//* Selects all elements in the document
//title[@*] Selects all title elements which have any attribute

 

Selecting Several Paths

By using the | operator in an XPath expression you can select several paths. In the table below we have listed some path expressions and the result of the expressions:

Path Expression Result
//book/title | //book/price Selects all the title AND price elements of all book elements
//title | //price Selects all the title AND price elements in the document
/bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document

 

The XML Example Document

We will use the following XML document in the examples below.

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore> 

 

XPath Axes

An axis defines a node-set relative to the current node.

AxisName Result
ancestor Selects all ancestors (parent, grandparent, etc.) of the current node
ancestor-or-self Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself
attribute Selects all attributes of the current node
child Selects all children of the current node
descendant Selects all descendants (children, grandchildren, etc.) of the current node