本文介绍了如何从xml文件中选择一个节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的xml文件


<?xml version="1.0" encoding="UTF-8"?>
<bookstore>

<book category="cooking">
<book>
	<bookID>1111</bookID>
</book>
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>

<book category="children">
<book>
	<bookID>54655</bookID>
</book>
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>

<book category="web">
<book>
	<bookID>5556</bookID>
</book>
<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" cover="paperback">
<book>
	<bookID>1111</bookID>
</book>
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>

</bookstore>

推荐答案


Dim doc
Set doc = CreateObject("Msxml2.DOMDocument.3.0")
doc.async = False
If doc.load(Server.MapPath("file.xml")) Then
  doc.setProperty "SelectionLanguage", "XPath"
  For Each book In doc.selectNodes("bookstore/book")
    Response.Write book.selectSingleNode("title").text & "<br>"
  Next
Else
  Response.Write doc.parseError.reason
End If


这篇关于如何从xml文件中选择一个节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 18:08