I am new to XPath and XML. I was wondering if there is an XPath expression to select all the attribute names and their respective values from an entire XML document.
As a simpler example to what I have:
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
<money currency="Dollars"></money>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
<money currency="Dollars"></money>
</book>
<book category="WEB">
<title lang="en">XQuery Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan Nagarajan</author>
<year>2003</year>
<price>49.99</price>
<money currency="Euros"></money>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
<money currency="Dollars"></money>
</book>
</bookstore>
I want this:
category : COOKING
lang : en
currency : Dollars
category : CHILDREN
lang : en
currency : Dollars
category : WEB
lang : en
currency : Euros
category : WEB
lang : en
currency : Dollars
The thing is I want this expression to work for any XML document. Any other suggestions as to how I can do this are welcome as well. Thank you.
string(/*/book[1]/@category)
I'm sure you know this, but the way you phrased it might give the unaware a mistaken impression. – LarsH