这两天在w3school学习了xpath,但遇到了一些问题想请教大家。
"books.xml" :
<?xml version="1.0" encoding="ISO-8859-1"?><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>-------------------------------------------
这是我的测试代码:
<html>
<body>
<script type="text/vbscript">set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("books.xml")set nodes=xmlDoc.selectNodes("/bookstore/book[last()-1]")for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next</script>
</body>
</html>
-----------------------------------
set nodes=xmlDoc.selectNodes("/bookstore/book[last()-1]")的时候页面是空白的,而set nodes=xmlDoc.selectNodes("/bookstore/book[2]")是可以正确显示,请问这是为什么,并怎样解决。谢谢!
"books.xml" :
<?xml version="1.0" encoding="ISO-8859-1"?><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>-------------------------------------------
这是我的测试代码:
<html>
<body>
<script type="text/vbscript">set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("books.xml")set nodes=xmlDoc.selectNodes("/bookstore/book[last()-1]")for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next</script>
</body>
</html>
-----------------------------------
set nodes=xmlDoc.selectNodes("/bookstore/book[last()-1]")的时候页面是空白的,而set nodes=xmlDoc.selectNodes("/bookstore/book[2]")是可以正确显示,请问这是为什么,并怎样解决。谢谢!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货