2

我需要使用 VB6 更新 bkp_path 的属性值。

XML 文件

<ServerDetails>
    <Param src_path = "D:\Shapes\Rectangle" bkp_path = "D:\Colors\Red"/>
</ServerDetails>

我可以使用从 XML 文件中读取值

VB6 代码

Dim doc As New MSXML2.DOMDocument
Set doc = New MSXML2.DOMDocument
Dim success As Boolean
'Load Config.xml
success = doc.Load("\Config\config.xml")

If success = False Then
  MsgBox ("Unable to locate the configuration file")
  Exit Function
Else
  Dim nodeList As MSXML2.IXMLDOMNodeList

  Set nodeList = doc.selectNodes("/ServerDetails/Param")

  If Not nodeList Is Nothing Then
     Dim node As MSXML2.IXMLDOMNode

     For Each node In nodeList
        srcpath = node.selectSingleNode("@src_path").Text
        bkpPath = node.selectSingleNode("@bkp_path").Text            
     Next node
  End If
End If

但无法弄清楚如何更新属性值。

4

2 回答 2

3

您需要获取对节点对象的引用,然后调用setAttribute()以指定新值:

node.setAttribute "bkp_path", "wibble"

您的代码还会从所有节点读取值,Param但您可能只想使用第一个节点或更新特定节点。

于 2012-05-08T13:48:43.047 回答
2

这成功了:

node.selectSingleNode("@bkp_path").Text = "D:\Colors\Blue"

于 2012-05-10T10:04:24.460 回答