String attributes

Build 1501 on 14/Nov/2017  This topic last edited on: 5/Aug/2014, at 16:53

The XML representation of a string attribute is the string itself as either the value of an XML attribute:

<gn4:story name="story name". . .>

or the text inside an XML element:

<gn4:story>

  <gn4:title>Story title<gn4:title>

  . . . 

</gn4:story>

Use the equality operator on this XML attributes or elements to search for string attributes with a specific value, e.g.:

gn4:story[@name=’story name’]

returns all stories named ‘story name’.

Use the ‘contains()’, ‘starts-with()’ and ‘fn:ends-with()’ functions to search for string attributes containing / starting with / ending with specific values, e.g.

gn4:story[contains(gn4:title,'title')]

returns all stories with a title containing ‘title’ in any position.

String attributes with a maximum length of more than 1300 characters are stored in the database as text columns instead than normal string columns; this limits the kind of tests that can be used when creating queries, because text columns cannot be directly compared to a value. For example the ‘summary’ attribute of the story objects in the standard schemas has a maximum length of 100,000, hence it is stored in a text column, and so a query using direct comparison:

gn4:story[gn4:summary='the summary']

fails with the error:

'gn4:summary' cannot be compared: it evaluates to a long text instead than a string (ERR1332)

It is still possible to do searches on such attributes using the functions listed above to do partial comparisons, e.g.

gn4:story[contains(gn4:summary,'summary')]

works fine, returning all stories with a summary containing the word ‘summary’.

Note that 1300 is the length limit in version 1.5, it could change in future versions.