Difference between revisions of "XPath queries"

From OpenKM Documentation
Jump to: navigation, search
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
Can be found more information about XPATH in http://www.w3.org/TR/xpath20/
+
{{TOCright}} __TOC__
  
== Examples ==
+
XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).
'''locked documents'''
 
 
//element(*, okm:document)[@jcr:lockOwner]
 
  
'''locked documents by user pavila'''
+
You can learn more about XPATH at http://www.w3.org/TR/xpath20/.
  
//element(*, okm:document)[@okm:author='pavila']
+
== Examples ==
 
+
=== Locked documents ===
'''search documents by content'''
+
<source lang="xml">
 
+
//element(*, okm:document)[@jcr:lockOwner]
//element(*, okm:document)[jcr:contains(okm:content, 'linux')]
+
</source>
 
 
'''folders created by user pavila'''
 
  
//element(*, okm:folder)[@okm:author='pavila']
+
=== Locked documents by user therol ===
 +
<source lang="xml">
 +
//element(*, okm:document)[@okm:author='therol']
 +
</source>
  
'''example of complex query, documents with content linux and keyword ubuntu'''
+
=== Search documents by content ===
 +
<source lang="xml">
 +
//element(*, okm:document)[jcr:contains(okm:content, 'linux')]
 +
</source>
  
//element(*,okm:document)[jcr:contains(okm:content,'linux') and jcr:contains(@okm:keywords,'ubuntu')]
+
=== Folders created by user potas ===
 +
<source lang="xml">
 +
//element(*, okm:folder)[@okm:author='potas']
 +
</source>
  
'''dereference'''
+
=== Example of complex query ===
+
Documents with content linux and keyword ubuntu:
//element(*, nt:linkedFile)/jcr:deref(@jcr:content, '*')[jcr:contains(., 'foo')]
+
<source lang="xml">
 +
//element(*,okm:document)[jcr:contains(okm:content,'linux') and jcr:contains(@okm:keywords,'ubuntu')]
 +
</source>
  
Note in the examples we're making queries from repository root node, but really the queries might be done from /jcr:root/okm:root/ - that's the taxonomy node - for example the locked documents might be done as
+
=== Dereference ===
 +
<source lang="xml"> 
 +
//element(*, nt:linkedFile)/jcr:deref(@jcr:content, '*')[jcr:contains(., 'foo')]
 +
</source>
  
/jcr:root/okm:root//element(*, okm:document)[@jcr:lockOwner]
+
{{Note|In the examples we're making queries from repository root node, but really the queries might be done from /jcr:root/okm:root/ - that's the taxonomy node - for example the locked documents might be done as
 +
  /jcr:root/okm:root//element(*, okm:document)[@jcr:lockOwner]
 +
}}
  
 
== Type restrictions ==  
 
== Type restrictions ==  
 
We can specify the type of node that query returns. Restrictions include inheritage all subtype are included as possible results. The function element is used to evaluate a node type.
 
We can specify the type of node that query returns. Restrictions include inheritage all subtype are included as possible results. The function element is used to evaluate a node type.
  
 
+
=== For example the node folders ===
'''for example the node folders'''
+
<source lang="xml">
 
+
//element(*, okm:folder)
//element(*, okm:folder)
+
</source>
 
 
  
 
== Property restrictions ==
 
== Property restrictions ==
 
A query can have property restrictions. The operators used are (=, !=, <, <=, >, >=) in addtion there's some extra operators like jcr:like() and jcr:contains().
 
A query can have property restrictions. The operators used are (=, !=, <, <=, >, >=) in addtion there's some extra operators like jcr:like() and jcr:contains().
  
'''getting folders with author pavila'''
+
=== Getting folders with author pito ===
 
+
<source lang="xml">
//element(*, okm:folder)[@okm:author = 'pavila']
+
//element(*, okm:folder)[@okm:author = 'pito']
 
+
</source>
'''documents name starting with linux'''
 
 
 
//element(*, okm:document)[jcr:like(@okm:name, 'linux%')]
 
 
 
'''documents with indexed content jackrabbit'''
 
  
//element(*, okm:resource)[jcr:contains(., 'jackrabbit')]/@jcr:path
+
=== Documents name starting with linux ===
 +
<source lang="xml">
 +
//element(*, okm:document)[jcr:like(@okm:name, 'linux%')]
 +
</source>
  
 +
=== Documents with indexed content jackrabbit ===
 +
<source lang="xml">
 +
//element(*, okm:resource)[jcr:contains(., 'jackrabbit')]/@jcr:path
 +
</source>
  
 
== Order ==
 
== Order ==
 
At ends query can be indicated the order of results.
 
At ends query can be indicated the order of results.
  
'''ordering by name'''
+
=== Ordering by name ===
 
+
<source lang="xml">
  //element(*, okm:document)[@okm:keywords != ''] order by @okm:name
+
//element(*, okm:document)[@okm:keywords != ''] order by @okm:name
 
+
</source>
 
 
Normally is used jcr:score to ordering, that indicates de ranking of the results.
 
 
 
  
 +
Usually is used jcr:score to ordering, that indicates de ranking of the results.
  
 
[[Category: Administration Guide]]
 
[[Category: Administration Guide]]
[[Category: OKM Network]]
 

Latest revision as of 16:50, 11 December 2012

XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document. XPath was defined by the World Wide Web Consortium (W3C).

You can learn more about XPATH at http://www.w3.org/TR/xpath20/.

Examples

Locked documents

 
//element(*, okm:document)[@jcr:lockOwner]

Locked documents by user therol

 
//element(*, okm:document)[@okm:author='therol']

Search documents by content

 
//element(*, okm:document)[jcr:contains(okm:content, 'linux')]

Folders created by user potas

 
//element(*, okm:folder)[@okm:author='potas']

Example of complex query

Documents with content linux and keyword ubuntu:

 
//element(*,okm:document)[jcr:contains(okm:content,'linux') and jcr:contains(@okm:keywords,'ubuntu')]

Dereference

  
//element(*, nt:linkedFile)/jcr:deref(@jcr:content, '*')[jcr:contains(., 'foo')]

Nota clasica.png In the examples we're making queries from repository root node, but really the queries might be done from /jcr:root/okm:root/ - that's the taxonomy node - for example the locked documents might be done as
 /jcr:root/okm:root//element(*, okm:document)[@jcr:lockOwner]

Type restrictions

We can specify the type of node that query returns. Restrictions include inheritage all subtype are included as possible results. The function element is used to evaluate a node type.

For example the node folders

//element(*, okm:folder)

Property restrictions

A query can have property restrictions. The operators used are (=, !=, <, <=, >, >=) in addtion there's some extra operators like jcr:like() and jcr:contains().

Getting folders with author pito

//element(*, okm:folder)[@okm:author = 'pito']

Documents name starting with linux

//element(*, okm:document)[jcr:like(@okm:name, 'linux%')]

Documents with indexed content jackrabbit

//element(*, okm:resource)[jcr:contains(., 'jackrabbit')]/@jcr:path

Order

At ends query can be indicated the order of results.

Ordering by name

//element(*, okm:document)[@okm:keywords != ''] order by @okm:name

Usually is used jcr:score to ordering, that indicates de ranking of the results.