如何写vbscript
哪个应该在 XML 文件中搜索特定节点并将该节点的值替换为另一个值?
到目前为止,我可以读取节点并获取值。
set objXML = CreateObject("Microsoft.XMLDOM")
objXML.async = "false"
objXML.load("E:\sage2\test.xml")
Set Root = objXML.documentElement
For Each x In Root.childNodes
if x.nodename="showList" then
plot=x.text
msgbox plot
end if
Next
请给我建议一些示例,该示例应该读取 xml 文件中的特定节点并替换该节点的值。
最佳答案
这是一个在 VBScript 中的简单 XML 编辑和保存示例。我建议使用 Xpath 来选择您的节点,而不是在子节点上循环,您可以提供您的 XML 以获得更详细的答案。
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.load "MYFILE.xml"
'Locate the desired node
'Note the use of XPATH instead of looping over all the child nodes
Set nNode = xmlDoc.selectsinglenode ("//parentnode/targetnode")
'Set the node text with the new value
nNode.text = "NEW VALUE"
'Save the xml document with the new settings.
strResult = xmldoc.save("MYFILE.xml")
关于VBScript 在 XML 节点中查找节点并替换值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7830215/