开发者

Selecting a Child in xPath

开发者 https://www.devze.com 2023-01-13 20:24 出处:网络
Looking at 开发者_高级运维w3schools for xPath (feel free to give me other references), you can select all the children of bookstore, but what if I wanted to only select the second book element? How ca

Looking at 开发者_高级运维w3schools for xPath (feel free to give me other references), you can select all the children of bookstore, but what if I wanted to only select the second book element? How can I do that?

<?xml version="1.0" encoding="ISO-8859-1"?>

<bookstore>

<book>
  <title lang="eng">Harry Potter</title>
  <price>29.99</price>
</book>

<book>
  <title lang="eng">Learning XML</title>
  <price>39.95</price>
</book>

</bookstore>


You could select the n-th element with [n], e.g.

/bookstore/book[2]

See "Predicates" in http://www.w3schools.com/xsl/xpath_syntax.asp for detail.

0

精彩评论

暂无评论...
验证码 换一张
取 消