How can I get all the ids of xml nodes via xquery?

I would like to get all the ids of xml nodes via xquery

I am trying this line but does not work(returns empty characters)

xquery doc('MYdb/MY.xml')/ROOT/*/string(@ID)

the xml is like this

ROOT
<NODE>
<ID>CP1</ID>
<..>
</NODE>
<NODE>
<ID>CP2</ID>
<...>
</NODE>
...
</ROOT>

I want to receive a string like this CP1,CP2,CP3....

Answers


That would be

fn:doc("MYdb/MY.xml")//ID/fn:string()

because your ids are not attributes but plain elements.

The // prefix will get all ID elements from every level of your document tree

HTH

Peter


Need Your Help

Need help understanding sessions and user profile

asp.net asp.net-mvc

I'm currently planning my web application. I was thinking using Session to store user profile (user name, current database, permissions, etc...). Common scenario is where user opens several tabs for