XML DOM使用Xpath后,对节点集循环遍历的问题

大虾哥哥 2008-08-06 09:40:27
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>
</bookstore>


js代码如下:
<html>
<body>
<script type="text/vbscript">

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("/example/xpth/books.xml")

set nodes=xmlDoc.selectNodes("/bookstore/book/price/text()")

for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next

</script>
</body>
</html>


显示结果如下:
30.00
29.99

我想问的是
for each x in nodes
document.write("<xmp>")
document.write(x.xml)
document.write("</xmp>")
next

这段代码中:for each x in nodes .....next 这个循环是js里面定义的吗?还是xml dom里面定义的?document.write("<xmp>")是xhtml的标签,它表示什么意思?
...全文
384 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
大虾哥哥 2008-08-06
  • 打赏
  • 举报
回复
orz_ORZ_orz 老大,你的意思是:用PRE或者SAMP标签来替换XMP标签,吧,那PRE的意思我查了一下,
pre 标签 -- 可以把原文件中的空格,回车,换行,tab键表现出来。那xmp标签的意思应该也是这样吧。
多谢orz_ORZ_orz
orz_ORZ_orz 2008-08-06
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 orz_ORZ_orz 的回复:]
对xmp的解释是:Use of this element is no longer recommended. Use the PRE or SAMP element instead
替换吧,楼主
[/Quote]

见2F
大虾哥哥 2008-08-06
  • 打赏
  • 举报
回复
呵呵,没细看,你说了我才发现脚本是vbscript的。多谢了。那document.write("<xmp>")表示什么意思呢?请教各位。
orz_ORZ_orz 2008-08-06
  • 打赏
  • 举报
回复
对xmp的解释是:Use of this element is no longer recommended. Use the PRE or SAMP element instead
替换吧,楼主
orz_ORZ_orz 2008-08-06
  • 打赏
  • 举报
回复
1.<script type="text/vbscript">
for each x in nodes .....next

你用的是vbscript,非javascript是也。。。
2未知,没见过

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧