cancel
Showing results for 
Search instead for 
Did you mean: 

Xpath support in Alfresco

greglenain
Champ in-the-making
Champ in-the-making
Hello,

To debug Alfresco XPath queries, I use the Node Browser.

Simple queries work fine:
./app:company_home/cm:folder1/cm:folder2/cm:file3

But slightly complex ones seem not to be supported.
For example, the following query:
./*[@alf:name='myFile']
returns a nice
Search failed due to: java.lang.UnsupportedOperationException

What are the limits of the Xpath support in Alfresco?

Thanks
4 REPLIES 4

rbramley
Champ in-the-making
Champ in-the-making
Have you tried replacing the alf with cm?

It does support more complex queries (from http://www.alfresco.org/forums/viewtopic.php?t=44) e.g.:

./*[@cm:name = 'someFolder' and subtypeOf('qname_of_folder')]/*[@cm:name = 'possibleOtherFolders' and subtypeOf('qname_of_folder')]/*[@cm:name = 'fileName' and subtypeOf('qname_of_file'))


You can even create your own functions by implementing org.jaxen.Function and then registering it with the XPathFunctionContext (see NodeServiceXPath).

greglenain
Champ in-the-making
Champ in-the-making
I've tried to replace the alf namespace with cm. It looks like:
./*[@cm:name = 'myFolder']/*[@cm:name = 'myFile.myExt']

But it still doesn't work (always the not-so-nice Search failed due to: java.lang.UnsupportedOperationException).

Can the Node Browser really deal with the XPath syntax?

Where to find examples of org.jaxen.Function and XPathFunctionContext implementations?

Thanks

davidc
Star Contributor
Star Contributor
There are two implementations of XPath support in Alfresco; the first is backed by Lucene, the second is backed by the NodeService.

The NodeService implementation provides much more XPath coverage than the Lucene implementation including Predicate support.  The UnsupportedOperationException is a weak message indicating the lack of Predicate support in the Lucene based implementation - I'm sure we'll implement that at some time.

In the NodeBrowser, you can select the kind of search to perform (one of noderef, xpath, lucene and selectnodes);  xpath = lucene based xpath, selectnodes = node service based xpath.

So, you can perform the following search ./*[@cm:name='Company Home'] with selectnodes in the node browser.

Underneath, xpath maps to the SearchService.query(…, SearchService.LANGUAGE_XPATH, …) method and selectnodes maps to SearchService.selectNodes(…) method.

greglenain
Champ in-the-making
Champ in-the-making
Fine!

When processed with a node service based search (selectnodes), all the Xpath queries I struggled with are perfectly working on a V1.2RC1 repository.

Furthermore, to rename a folder no more prevents the query service from searching its descendants.

Thank you.