这两天在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>
这是我的测试代码:(测试代码文件和books.xml在同一个文件夹)
<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>
这是我的测试代码:(测试代码文件和books.xml在同一个文件夹)
<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]")是可以正确显示,请问这是为什么,并怎样解决。谢谢!
解决方案 »
- 关于正则表达式非捕获性分组的疑问
- 查看网页里音乐文件的地址?
- 关于正折表达式,请大家帮忙看看,多谢了!
- 一种打断被闭包引入的循环引用的窍门是添加另外一个闭包,应该如何理解?
- 十万火急,求一条正则表达式,非常感谢
- JS判断数字是否只包含数字1-7
- <table width="100%" hight="80" onselectstart="event.returnValue=false></table>中onselectstart="event.returnValue=false"的作用是
- Javascript中怎样查找,引用<div>元素.已经知<div>的ID
- 关于使用<object>代替<div>做动态菜单的问题,请高手相助
- 两个select的问题
- html 背景怎么画网状交叉线条?
- 已知行驶IP,如何调用Google API把行驶轨迹显示在Google地图上
xmlDoc.async=false
xmlDoc.load("books.xml")
xmlDoc.setProperty "SelectionLanguage", "XPath"
set nodes=xmlDoc.selectNodes("/bookstore/book[(last()-1)]")
http://msdn.microsoft.com/en-us/library/ms760290%28VS.85%29.aspx
http://msdn.microsoft.com/en-us/library/ms766391%28VS.85%29.aspx
http://support.microsoft.com/?scid=kb%3Ben-us%3B288913