本文介绍了在DOM中使用getNamedItem函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过Vb脚本在xml DOM中使用函数getNamedItem,但是它永远无法正常工作。下面是代码和XMl文件。
,请帮助我找出错误,在此先感谢。
Am trying to use the function getNamedItem in xml DOM through Vb script but it never works. Below is the piece of code and XMl document.Please help me in finding out the error, thanks in advance.
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>
推荐答案
错误的引号:
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()的示例用法:
Sample use of getNamedItem():
...
Dim Node : Set Node = child.item(1)
WScript.Echo Node.attributes.getNamedItem("category").value
这篇关于在DOM中使用getNamedItem函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!