tags:

views:

138

answers:

2

I am trying to match against ids stored as list element using XQuery.

For example,

<data>
 <item>
  <name>foo</name>
  <intValues>1 2 3 4 5</intValues>
 </item>
 <item>
  <name>bar</name>
  <intValues>6 7 8 9 10</intValues>
 </item>
</data>

is it possible to return items that include 3 in the intValues?

+2  A: 

is it possible to return items that include 3 in the intValues?

This XPath expression selects exactly all item elements that have a '3' as one of the list of values contained in their intValues child:

   /*/item['3' = tokenize(intValues, ' ')]

Dimitre Novatchev
tokenize(element, ' ') worked beautifully. +1.
eed3si9n
+2  A: 

If your xml file has a schema and you are using a schema-aware processor then the query is just

/data/item[intValues = 3]

otherwise, as Dimitre suggests you will have to tokenize this manually.

Oliver Hallam
+1 for schema-aware processor.
eed3si9n