Reference attributes

Build 1501 on 14/Nov/2017  This topic last edited on: 21/Mar/2016, at 18:52

The XML representation of a reference attribute is an XML element named as the attribute, with the database id of the referenced object in its ‘idref’ attribute, and containing a sub-element ‘nav:refObject’ holding the complete XML representation of the referenced object; e.g. something like this:

 <gn4:story id="obj33478". . .>

   . . .

  <gn4:folderRef idref="obj31860">

      <nav:refObject idref="obj31860">

        <gn4:folder id="obj31860" . . . >

          . . .

        </gn4:folder>

      </nav:refObject>

    </gn4:folderRef>

   . . .

 </gn4:story>

for the folder reference of a story. Based on this XML representation, the query to return all stories in a folder with database id 31860 is:

 gn4:story[gn4:folderRef/@idref='obj31860']

Note how the id must be specified as a string with the ‘obj’ prefix, because this is its XML representation. Use the ‘nav:refObject’ sub-element to create conditions based on the attributes of the referenced object, for example

 gn4:story[gn4:folderRef/nav:refObject/gn4:folder/@path='/system/users/Guest']

returns all the stories in the folder with path ‘/system/users/Guest’.

The XML representation of every object includes a ‘nav:referencing’ sub-element listing all the objects that reference the current one (again, like the standard navigation XML), e.g. for a folder:

 <gn4:folder id="obj31860" . . .>

   . . .

  <nav:referencing>

      <nav:referencingBy attrName="story.folderRef">

        <nav:refs handle="1">

          <nav:refObject idref="obj33477">

            <gn4:story . . .>

              . . .

            </gn4:story>"

          </nav:refObject>

           . . .

        </nav:refs>

      </nav:referencingBy>

      . . .

    </nav:referencing>

   . . .

 </gn4:folder>

Use this element to create queries based on the referencing (as opposed to the referenced) objects, e.g.

 gn4:folder[nav:referencing/nav:referencingBy[@attrName='story.folderRef']

   /nav:refs/nav:refObject/@idref='obj33477']

returns the folder containing (i.e. referenced by) the story with database id 33477, and

 gn4:folder[nav:referencing/nav:referencingBy[@attrName='story.folderRef']

   /nav:refs/nav:refObject/gn4:story/gn4:title='My title']

returns all the folders containing stories titled ‘My title’.

Note that the referencing element used by GNQuery lists ALL possible referencing attributes, whereas the navigation XML does not contains the derived referencing attributes – so the GNQuery XML contains ‘folderObject.folderRef’, ‘archiveObject.folderRef’, ‘story.foldeRef’, ‘image.folderRef’ etc. (all attributes derived from the root ‘folderObject.folderRef’), the navigation XML contains only ‘folderObject.folderRef’.