我想使用 VB.net 在 Visual Studio 中从头开始创建 XML 文件
我找到了在线示例,但我很难理解如何在某些情况下添加属性和其他情况下的子元素。加上我的顶部元素有其他元素。我的意思是我的格式更长,但它看起来像下面的例子:
-<CompanyFile>
-<Companybranch name="something">
-<Customer>
<name></name>
<age></age>
<address>
<addreesLine > </addreesLine>
<address>
</Customer>
</Companybranch>
</CompanyFile>
Run Code Online (Sandbox Code Playgroud)
我找到了一个具有基本 XML 格式的链接。
Imports System.Xml
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim writer As New XmlTextWriter("product.xml", System.Text.Encoding.UTF8)
writer.WriteStartDocument(True)
writer.Formatting = Formatting.Indented
writer.Indentation = 2
writer.WriteStartElement("Table")
createNode(1, "Product 1", "1000", writer)
createNode(2, "Product 2", "2000", writer)
createNode(3, "Product 3", "3000", writer)
createNode(4, "Product 4", "4000", writer)
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close() …Run Code Online (Sandbox Code Playgroud)