我在页面http://www.w3schools.com/xml/xml_xpath.asp中有类似于xml的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>
</book>
<book category="children">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</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>
</book>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
问题是如何使用与某个值对应的元素返回此文档?应该如何编写XPath或XQuery命令?
例如,搜索标题包含“ Learning”,则返回的xml文档应类似于:
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="web">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
如何得到这个结果?
另一个问题,如何使用忽略字符的大小写进行搜索,因此“ learNING”应返回相同的结果?
使用XQuery可以执行以下操作:
<bookstore>
{
for $d in //book[contains(lower-case(title),'learning')]
return $d
}
</bookstore>
请注意,只有一个<bookstore>
包装所有<book>
返回的匹配元素,并注意lower-case()
在匹配过程中使用函数“忽略”书名的字符大小写。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句