VBScript 在 XML 节点中查找节点并替换值

标签 vbscript

如何写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/

相关文章:

python - 使用批处理将文件和文件夹复制到另一个路径

vbscript - 测试完整工具和 VB 脚本教程

.net - 在 VBScript (COM-interop) 中确定 .Net 方法后缀号

vbscript - 带参数的 Shell.Run

vbscript - 通过VBS访问MDB

sql-server - ADODB.记录集 : Operation is not allowed when the object is closed

vbscript - 经典ASP(VBScript)仅显示第一个图像(YouTube图像)

c# - 如何使用命令行回收远程机器上的应用程序池

vbscript - VBScript 中的 Try-Catch-End Try 似乎不起作用

asp-classic - 或 vbscript 中的运算符