cancel
Showing results for 
Search instead for 
Did you mean: 

XPath query in xml content

ananius
Champ in-the-making
Champ in-the-making
Hi,

is it possible to use xpath query in xml documents, which are stored in Alfresco as single text contents?
For example, if I have several 'testDocument'-nodes in repository, which contain xml documents as content. Content could be eg
<aaa>
  <bbb attr1="foo"/>
</aaa>
Now I would like to search all testDocuments with some condition, for example with following xpath expression:
//testDocument/aaa/bbb[@attr1='foo']
Is this possible?
6 REPLIES 6

kevinr
Star Contributor
Star Contributor
No that is not currently possible directly.

However, using the templating language API built into Alfresco, it is possible to locate documents (either by XPath, name or Lucene search) and then walk the DOM of a document as XML nodes.

Take a look at this document for info on those features:
http://www.alfresco.org/mediawiki/index.php/Template_Guide
The example at the very bottom of the page shows how to walk a document as an XML DOM.

Hope this helps,

Kevin

manuelgentile
Champ in-the-making
Champ in-the-making
Hi Kevin
I wonder if in ther Alfresco 1.3 or in the next 1.4 there are this feature?

It will be very useful use xpath query in xml documents.

Thanks

In any case what do yuo think is the best solution to achieve this goal?

simon
Champ in-the-making
Champ in-the-making
Does this mean (and is this still correct in 1.4) that I can not use XPath to search for attributes in a single XML document? No fancy stuff here, I only want to use XPath IN an XML tree (read from some document in Alfresco) to find the attribute I'm looking for. Can this be done from a Freemarker template? I have the xmlNodeModel in a variable and would like to use XPath on this variable…

kevinr
Star Contributor
Star Contributor
Does this mean (and is this still correct in 1.4) that I can not use XPath to search for attributes in a single XML document? No fancy stuff here, I only want to use XPath IN an XML tree (read from some document in Alfresco) to find the attribute I'm looking for. Can this be done from a Freemarker template? I have the xmlNodeModel in a variable and would like to use XPath on this variable…

Yes you can use the FreeMarker API to do this. The original poster was talking about being able to use xpath like statements to search within XML documents from the simple/advanced search in the web-client - a very different issue!

Thanks,

Kevin

simon
Champ in-the-making
Champ in-the-making
Thanks Kevin… one more question though: how? Tried some things out but couldn't get it to work. Is there some documentation for this? I found some JavaScript references but would like to do this with Freemarker, any idea how to trigger this?

kevinr
Star Contributor
Star Contributor
My mistake, you can't use XPath in FreeMarker, you have to walk the DOM or use the 'visit' and 'recurse' directives instead.

Thanks,

Kevin
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.