用vbscript读取xml文件 [英] reading xml file with vbscript
问题描述
我正在尝试编写vbscript来自动执行存储阵列的配置.我在弄清楚如何最好地浏览XML方面遇到了一些困难.
I am trying to write a vbscript to automate the configuration of a storage array. I'm having some difficulty figuring out how best to navigate the XML.
我的XML的示例部分:
An example section of my XML:
<SERVER>
<INTERFACE>
<PORT>0</PORT>
<IPADDRESS>192.168.1.1</IPADDRESS>
<NETMASK>255.255.255.0</NETMASK>
</INTERFACE>
<INTERFACE>
<PORT>1</PORT>
<IPADDRESS>192.168.1.2</IPADDRESS>
<NETMASK>255.255.255.0</NETMASK>
</INTERFACE>
</SERVER>
所以我想遍历每个接口(实际上有5个),并在正确的接口上设置适当的IP和网络掩码.
So I want to iterate through each interface (there is 5 in reality) and set the appropriate IP and netmask on the correct interface.
我目前正在这样做:
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("example.xml")
Set Root = objXMLDoc.documentElement
Set NodeList = Root.getElementsByTagName("interface")
port = 0
For Each Elem In NodeList
WScript.Echo "Port " & port & " has IP address of " & Elem.text
port = port + 1
Next
,但是必须有一种更简洁的方法来执行此操作,在该方法中,我可以选择接口部分并读取端口ipaddress&网络掩码,发出命令,然后进入下一个界面?
but there must be a cleaner way do doing this where I can select the interface section and read in the port, ipaddress & netmask, issue the command and then move into the next interface?
谢谢.
推荐答案
第一种方法:
For Each Elem In NodeList
SET port = Elem.getElementsByTagName("Port")(0)
SET ip = Elem.getElementsByTagName("IPADDRESS")(0)
WScript.Echo "Port " & port.nodeValue & " has IP address is " & ip.nodeValue
Next
这篇关于用vbscript读取xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!