我正在尝试用新值替换找到的属性,但似乎无法获得它....
XML示例
<department sysid="1" name="a" minAmt="0.00" maxAmt="0.00" isAllowFS="0" isNegative="0" isFuel="0" isAllowFQ="0" isAllowSD="0" isBL1="0" isBL2="0" isMoneyOrder="0">
<category sysid="0" />
代码
For Each node In xmldoc.SelectNodes("//department")
'For Each node In nodeDepartment
Dim a = node.getAttribute("isFuel").ToString
If a = 0 Then
node.ChildNodes.Item(1).Attributes.getNamedItem("sysid").Value = "400"
Dim sName As String = node.getAttribute("name").ToString 'I get the value here
If Trim(sName) = "" Then
node.Attribute("name") = "A" 'I Error on this line
End If
End If
lCount += 1
Next
答案 0 :(得分:1)
您需要使用SetAttribute方法而不是GetAttribute。
If Trim(sName) = "" Then
node.SetAttribute("name", "A")
End If