2015-10-19 40 views
1

我想更換新的價值發現的屬性,但似乎無法得到它....使用的XMLDocument - 如何更改屬性值

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 

回答

1

您需要使用SetAttribute方法代替GetAttribute。

If Trim(sName) = "" Then 

    node.SetAttribute("name", "A") 

End If 
+0

我試過類似的東西,但語法錯了。謝謝! – Xardoz

+0

不客氣。如果這解決了您的問題,請不要忘記將其標記爲已接受的答案。 – N0Alias