[英]Edit attribute values of XML using VB6
I need to update the attribute value of bkp_path using VB6. 我需要使用VB6更新bkp_path的属性值。
<ServerDetails>
<Param src_path = "D:\Shapes\Rectangle" bkp_path = "D:\Colors\Red"/>
</ServerDetails>
I'm able to read values from XML file using 我可以使用从XML文件读取值
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
but can't figure out how to update attribute values. 但无法弄清楚如何更新属性值。
You need to get a reference to the node object then call setAttribute()
to specify the new value: 您需要获取对节点对象的引用,然后调用setAttribute()
来指定新值:
node.setAttribute "bkp_path", "wibble"
Your code also reads the values from all the Param
nodes but you may want to only use the first or update a specific one. 您的代码还从所有Param
节点读取值,但是您可能只想使用第一个或更新特定的值。
这达到了目的:
node.selectSingleNode("@bkp_path").Text = "D:\\Colors\\Blue"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.