如何编写一个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")