If I have several Section
elements in an XML document, what XQuery do I use to get a list of all the name
values?
<Section name="New Clients" filePath="XNEWCUST.TXT" skipSection="False">
If I have several Section
elements in an XML document, what XQuery do I use to get a list of all the name
values?
<Section name="New Clients" filePath="XNEWCUST.TXT" skipSection="False">
In XPath 2.0 (which is a subset of XQuery) one would use the following expression to get a sequence of all string values of the "name" attributes of the "Section" elements:
for $attr in //Section/@name
return string($attr)
Do note that using the "//" abbreviation is typically a bad practice as this may require a whole (subtree) to be traversed. In any case where the structure of the document is known a more specific XPath expression (such as one using specific location steps) should be preferred.
//Section/@name
or
//Section/@name/string(.)
for the string values