我试图通过Vb脚本在xml DOM中使用函数getNamedItem但它永远不会工作。下面是一段代码和XMl文档。 请提前帮助我找出错误。
Set obj = CreateObject("Microsoft.xmldom")
obj.async = false
obj.load ("C:\Users\ACER\Desktop\Project Folder\Parsing XML\Books.xml")
Set root = obj.documentElement
Set child = root.childNodes
Set Node = child.item(1)
s=Node.getNamedItem('author')
Msgbox s
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>
答案 0 :(得分:0)
错误的引语:
getNamedItem('author') - use double quotes "
错误的功能:
getNamedItem - Returns IXMLDOMNode object for the specified attribute.
类似的东西:
Dim root : Set root = objMSXML.documentElement
Dim child : Set child = root.childNodes
Dim Node : Set Node = child.item(1)
Dim ndFnd : Set ndFnd = Node.selectSingleNode("author")
WScript.Echo ndFnd.text
会给你:
J K. Rowling
使用getNamedItem()的示例:
...
Dim Node : Set Node = child.item(1)
WScript.Echo Node.attributes.getNamedItem("category").value