這裏是XML文件和我的代碼。我需要更改<Value>
標記中的數字2509。下面的代碼找到<Value>SchoolFiles</Value>
,但之後跳出循環。我知道有一個更好的方式循環。如何使用VB.NET編輯XML文件
XML文件
<Filters>
<Filter>
<Name>ViewFolders</Name>
<ApplyToFiles>0</ApplyToFiles>
<ApplyToDirs>1</ApplyToDirs>
<MatchType>None</MatchType>
<MatchCase>0</MatchCase>
<Conditions>
<Condition>
<Type>0</Type>
<Condition>0</Condition>
<Value>SchoolFiles</Value>
</Condition>
<Condition>
<Type>0</Type>
<Condition>0</Condition>
<Value>DataImportFiles</Value>
</Condition>
<Condition>
<Type>0</Type>
<Condition>0</Condition>
<Value>2509</Value>
</Condition>
</Conditions>
</Filter>
</Filters>
Dim FileZillaXMLFilterFile As String = "C:\Users\Development\AppData\Roaming\FileZilla\filters.xml"
Dim myXmlDocument As XmlDocument = New XmlDocument()
myXmlDocument.Load(FileZillaXMLFilterFile)
Dim MyNode As XmlNode
Dim node As XmlNode
node = myXmlDocument.SelectSingleNode("//Filters")
'node = myXmlDocument.SelectSingleNode("//Filters/Filter/Conditions/Condition/Value")
For Each book As XmlNode In node.ChildNodes
Debug.Print(book.InnerText) '= Session("iCustID").ToString()
If Microsoft.VisualBasic.Left(book.InnerText, 11) = "ViewFolders" Then
For Each node4 As XmlNode In book.ChildNodes
If node4.Name = "Conditions" Then
'Debug.Print(node4.LastChild.Name)
For Each node5 As XmlNode In node4.ChildNodes
Debug.Print(node5.Name)
For Each node6 As XmlNode In node5.ChildNodes
Debug.Print(node6.Name)
If node6.Name = "Value" Then
Debug.Print(node6.InnerText)
For Each node7 As XmlNode In node6.ChildNodes
If node7.InnerText <> "SchoolFiles" And node7.InnerText <> "DataImportFiles" Then
'need to change 2509 to another numnber
Debug.Print(node7.InnerText)
End If
Next
End If
Next
Next
End If
Next
End If
Next
更改xml中的任何值都需要重寫整個xml文件。 – nelek
https://msdn.microsoft.com/en-us/library/system.xml.xmlnode.selectsinglenode(v=vs.110).aspx –