Xml 在DOM中使用getNamedItem函数
我试图通过Vb脚本在xml DOM中使用函数getNamedItem,但它从来都不起作用。下面是一段代码和XMl文档。 请帮我找出错误,提前谢谢Xml 在DOM中使用getNamedItem函数,xml,dom,vbscript,Xml,Dom,Vbscript,我试图通过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 = r
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>
日常意大利语
吉娅达·德·劳伦蒂斯
2005
30
哈利·波特
J K.罗琳
2005
29.99
错误的引用:
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()的示例用法:
以下是xml每日意大利语Giada De Laurentiis 2005 30.00 Harry Potter J K.Rowling 2005 29.99谢谢,一个问题IXMLDOMNode是什么意思?@user1925406-“IXMLDOMNode”是
getNamedItem()
返回的对象的类/类型名称。
...
Dim Node : Set Node = child.item(1)
WScript.Echo Node.attributes.getNamedItem("category").value