XQuery to get a list of attributes

If I have several Section elements in an XML document, then which XQuery do I use to list all name values?

 <Section name="New Clients" filePath="XNEWCUST.TXT" skipSection="False"> 
+4
source share
3 answers

In XPath 2.0 (which is a subset of XQuery), you can use the following expression to retrieve the sequence of all string values ​​for the "name" attributes of the "Section" elements:

 for $attr in //Section/@name return string($attr) 

Please note that using the abbreviation "//" is usually bad practice, as this may require moving the whole (subtree). In any case, when the document structure is known, a more specific XPath expression should be preferred (for example, one using specific location steps).

+5
source
 //Section/@name 

or

 //Section/@name/string(.) 

for string values

+1
source
  /Section/@name 
0
source

All Articles