【问题标题】:Locate XML node with specific attribute and change it找到具有特定属性的 XML 节点并更改它
【发布时间】:2014-06-30 17:32:02
【问题描述】:

我在这里查看了几个关于如何定位 XML 节点和更改属性的线程。但是,我找不到解决问题的方法:

我有一个 XML 节点,它下面有几个具有相同名称(但属性不同)的节点。例如:

<Configuration>
  <ConfigOptions>
    <add key="Localize" value="Off" />
    <add key="Cache" value="Database" />
    <add key= etc........

我需要使用一个简单的 VBScript 来定位 &lt;add&gt; 节点所在的 key="Cache",然后将值更改为其他值。

【问题讨论】:

标签: xml vbscript


【解决方案1】:

使用xpath syntax选择节点

Set xmlDoc = CreateObject("Msxml2.DOMDocument.6.0")
xmlDoc.load strXMLPath
Set node = xmlDoc.selectNodes("//Configuration/ConfigOptions/add[@key='Cache']")
strOldValue = node.item(0).attributes.getNamedItem("value").text

然后改变值

node.item(0).attributes.getNamedItem("value").text = strNewValue

然后保存xml文件

xmlDoc.save strXMLPath

【讨论】:

  • 这正是我一直在寻找并完成这项工作的。非常感谢!
猜你喜欢
  • 2013-12-12
  • 1970-01-01
  • 2015-05-18
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多