我有一个像这样的XML文件
<serverlist>
<server>
<id>1</id>
<ip>127.0.0.1</ip>
<port>11101</port>
<category sort="1">PVE</category>
<name raw_name="TEST">
<![CDATA[TEST]]>
</name>
我想只读取/重写127.0.0.1
并将其放在文本框中或从文本框放到文件中。
答案 0 :(得分:0)
它似乎是一个XML,所以你可以使用LinQ to XML。
获取值:
Private Function getValue(name As String) As String
Dim doc = XDocument.Load("YourFilePath")
Dim data = (From c In doc.Descendants(name)
Select c).First()
Return data.Value
End Function
设置值:
Private Sub setValue(name As String, value As String)
Dim doc = XDocument.Load("YourFilePath")
Dim data = (From c In doc.Descendants(name)
Select c).First()
data.ReplaceAll(value)
doc.Save("YourFilePath")
End Sub