节点中查找节点并替换值

节点中查找节点并替换值

本文介绍了VBScript 在 XML 节点中查找节点并替换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写一个 vbscript 来搜索 XML 文件中的特定节点并将该节点的值替换为另一个值?

How to write a vbscript which should search for a specific node in a XML file and replace the value of that node with another value?

到目前为止,我可以读取一个节点并获取值.

So far I can read a node and get the value.

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 文件中的特定节点并替换该节点的值.

please suggest me some example which should read a specific node in the xml file and replace the value of that node.

推荐答案

这是一个简单的 XML 编辑和保存在 VBScript 中的示例.我建议使用 Xpath 来选择您的节点,而不是循环遍历子节点,您可以提供您的 XML 以获得更详细的答案.

Here is a simple XML edit and save example in VBScript. I recommend lokking into using Xpath to select your node instead of looping over the child nodes, you can provide your XML for more detailed answer.

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 节点中查找节点并替换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 01:50