【发布时间】:2014-12-17 16:25:44
【问题描述】:
我想使用 xml 更新 vb.net 中的节点,但找不到合适的解决方案。
这就是我的阅读和写作能力:
If (IO.File.Exists(Application.StartupPath & "MyXML.xml")) Then
Dim document As XmlReader = New XmlTextReader("MyXML.xml")
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name = "port") Then
port = document.ReadInnerXml.ToString()
End If
End If
End While
Else
Dim settings As New XmlWriterSettings()
settings.Indent = True
Dim XmlWrt As XmlWriter = XmlWriter.Create("MyXML.xml", settings)
With XmlWrt
.WriteStartDocument()
.WriteComment("XML.")
.WriteStartElement("Data")
.WriteStartElement("Settings")
.WriteStartElement("port")
.WriteString("7008")
.WriteEndElement()
.WriteEndDocument()
.Close()
End With
End If
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
请更具体。代码应该做什么?它应该做什么?它会生成什么(如果有)错误消息?