VBScript在XML节点中查找节点并替换该值
发布时间:2020-12-16 23:21:38 所属栏目:百科 来源:网络整理
导读:如何编写一个vbscript,它应该搜索 XML文件中的特定节点,并用另一个值替换该节点的值? 到目前为止,我可以读取一个节点并获取值. set objXML = CreateObject("Microsoft.XMLDOM")objXML.async = "false"objXML.load("E:sage2test.xml")Set Root = objXML.do
如何编写一个vbscript,它应该搜索
XML文件中的特定节点,并用另一个值替换该节点的值?
到目前为止,我可以读取一个节点并获取值. set objXML = CreateObject("Microsoft.XMLDOM") objXML.async = "false" objXML.load("E:sage2test.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") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |