vb.net附加一个空标签,其格式为<data>

时间:2019-04-07 11:27:20

标签: xml vb.net tags append

我有一个由我的vb.net应用创建的Xml文件,如果找不到该文件的代码如下:

  If Not System.IO.File.Exists(Application.StartupPath & "\XML\DATA.xml") Then
            Dim myWriter As New XmlTextWriter((Application.StartupPath & "\XML\DATA.xml"), System.Text.Encoding.UTF8)
            myWriter.WriteStartDocument(True)
            myWriter.Formatting = Formatting.Indented
            myWriter.Indentation = 2

            myWriter.WriteStartElement("ID")

            myWriter.WriteEndDocument()
            myWriter.Close()

这会创建标签,如果不提供内部文本,该标签看起来像:

<DATA />

代替

<DATA></DATA>

除了我现在要附加<DATA />标记,除了现在,这真的不会打扰我,

Dim myDocXml As New XmlDocument()
        myDocXml.Load(Application.StartupPath & "\XML\DATA.xml")

Dim myNode As XmlNode = myDocXml.SelectSingleNode(".//DATA/ID")

        If myNode IsNot Nothing Then
            myNode.ChildNodes(0).InnerText = TextBox1.Text
        Else
            myeNode.Item(0).InnerText = TextBox1.Text
        End If

mysDocXml.Save(Application.StartupPath & "\XML\DATA.xml")

在这种情况下,我现在在调试对象引用未设置为对象实例时被提示。

如何附加这样的标签格式?

0 个答案:

没有答案