XQuery to get list of attributes

做~自己de王妃 提交于 2019-12-23 15:22:27

问题


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">

回答1:


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.




回答2:


//Section/@name

or

//Section/@name/string(.)

for the string values




回答3:


 /Section/@name


来源:https://stackoverflow.com/questions/324289/xquery-to-get-list-of-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!