All the data contained in a GN4, Tark4 or GNPortal system is represented in a standard way as XML, GNQuery uses this XML representation to write queries as XPath and XQuery expressions. In other words all the data contained in a system is seen as a virtual XML ‘file’:
<gn4:story id="obj33478" name="635e2bcd-7803-4a7d-b681-a7d6f865f417" . . .>
<gn4:title>From mobile 2</gn4:title>
. . .
</gn4:story>
<gn4:story id="obj33476" name="0941b3a9-87ab-4c18-8c17-71270d6600ea" . . .>
<gn4:title>From mobile 1</gn4:title>
. . .
</gn4:story>
. . . (all other stories) . . .
<gn4:image id="obj33477" name="image_47a560fd-1d45-4bde-861b-1a2a816c0f99" . . . >
<title>articleVersions</title>
. . .
</gn4:image>
. . . (all other images) . . .
. . . (all other objects of different types) . . .
and queries are XPath expressions executed on this XML – e.g. the expression
gn4:story
returns ALL stories in the system – being an XPath that matches all the story in the above XML. To find a story with a specific title:
gn4:story[gn4:title='My title']
that is an XPath matching all the gn4:story elements with a gn4:title sub-element containing the text 'My title'.
Query expressions specify objects attributes using their standard XML representation, so in the example above the story title is ‘gn4:title’ – because it is represented as a XML element; to get all the stories modified since August 1st use:
gn4:story[@modifiedDate>='2012-08-01T00:00:00Z']
because the last modification date is represented as an XML attribute:
<gn4:story id="obj33476" modifiedDate="2012-14-08T17:33:07Z" . . .>
. . .
</gn4:story>
Use the same logic to specify attributes with complex values, for example keywords are represented in XML like this:
<gn4:story id="obj33476". . .>
. . .
<gn4:keywords>
<gn4:item>architecture</gn4:item>
<gn4:item>bridges</gn4:item>
</gn4:keywords>
. . .
</gn4:story>
so to find all stories with a specific keyword use:
gn4:story[gn4:keywords/gn4:item='bridges']
To find the stories with ANY keyword use:
gn4:story[gn4:keywords/gn4:item]
i.e. all stories that have at least a ‘gn4:item’ sub-sub-element under their ‘gn4:keywords’ sub-element.
Note that the ‘gn4:keywords’ sub-element is always present – even if the story does not have any keyword, so
gn4:story[gn4:keywords]
is the same as
gn4:story
because the condition inside the brackets is always true.