XML:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
<location>DL</location>
</book>
<book category="children">
<title lang="es">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
<location>UP</location>
</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>
<location> DL</location>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
<location>dl </location>
</book>
<category>web</category>
</bookstore>
XPath表达式:
字符串(/ bookstore / book / @ category)
上面的XPath表达式仅返回book元素下的第一个属性的值:
烹饪
预期输出:
烹饪
孩子
网络
网络
我希望我的XPath表达式返回book元素的所有属性的字符串值。我提到了几篇文章,但找不到可以获取所有属性值的onw。
答案 0 :(得分:0)
在XPath 2和更高版本中,您可以使用/bookstore/book/@category/string()
。