x-path节点查询

被解析的代码如下:
<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>



1.选取title为Everyday Italian,并且title的lang为en的book节点的price.
//book[node()[@lang=""en""]/text() = ""Everyday Italian""]/price/text()
运行结果:30.00
小结:1.node()[@lang=""en""]方括号中直接取属性指的取node()的lang属性

2.选取bookstore下面名称为Everyday Italian的book
//bookstore/node()[*/text() = ""Everyday Italian"" ]
运行结果:
<book category="COOKING">
	<title lang="en">Everyday Italian</title>
	<author>Giada De Laurentiis</author>
	<year>2005</year>
	<price>30.00</price>
</book>

小结: 方括号如果不跟属性而是跟节点或者node(),*等,则表示取得当前node()的下一层节点。如:
node()[*/text() = ""Everyday Italian"" ]表示取得node()下的下一层所有节点,该节点的text()为Everyday Italian的节点。

3.选取作者名不为Everyday Italian,也不为Harry Potter的book的作者名称.
/bookstore/book[title/text() != ""Everyday Italian"" and title/text() != ""Harry Potter""]/author/text()
运行结果:
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
Erik T. Ray


x-path学习文档: http://www.w3school.com.cn/xpath/index.asp
x-path在线测试路径: http://www.w3school.com.cn/tiy/t.asp?f=xpth_select_cdnodes_first

你可能感兴趣的:(xml,F#,J#,asp)