VB.NET使用xml序列化数组
如何用VB.NET可以使用这样的 XML ,可以是控件台,也可以是生文件
<?xml version="1.0" encoding="gb2312"?>
<PurchaseOrder xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Items>
<Item>
<ItemID>aaa111</ItemID>
<ItemPrice>34.22</ItemPrice>
<Item>
<Item>
<ItemID>bbb222</ItemID>
<ItemPrice>2.89</ItemPrice>
<Item>
</Items>
</PurchaseOrder> xml序列化数组VB.NET
[解决办法]
http://www.111cn.net/net/XML/39351.htm
[解决办法]
http://blog.csdn.net/kaedei/article/details/3899045
[解决办法]
http://www.java2s.com/Code/VB/XML/XmlSerializerDemo.htm
[解决办法]
Private Sub createXML()
Try
Dim writer As New Xml.XmlTextWriter(Application.StartupPath & "/test.xml" , System.Text.Encoding.GetEncoding("gb2312"))
writer.Formatting = Xml.Formatting.Indented
writer.WriteRaw("<?xml version=""1.0"" encoding=""gb2312"" ?>")
'书写根元素
writer.WriteStartElement("PurchaseOrder")
writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema")
'添加次级元素
writer.WriteStartElement("Items")
writer.WriteStartElement("Item")
writer.WriteElementString("ItemID", "aaa111")
writer.WriteElementString("ItemPrice", "34.22")
writer.WriteEndElement()
writer.WriteStartElement("Item")
writer.WriteElementString("ItemID", "bbb222")
writer.WriteElementString("ItemPrice", "2.89")
writer.WriteEndElement()
writer.WriteFullEndElement()
writer.Close()
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
End Try
End Sub
Dim ds As New DataSet
ds.DataSetName = "Items"
Dim dt As New DataTable("Item")
Dim drow As DataRow
dt.Columns.Add(New DataColumn("ItemID", GetType(Integer)))
dt.Columns.Add(New DataColumn("ItemPrice", GetType(Integer)))
Dim i As Integer
For i = 3 To 10
drow = dt.NewRow
drow("ItemID") = i
drow(1) = i * i
dt.Rows.Add(drow)
Next
ds.Tables.Add(dt)
DataGridView1.DataSource = ds.Tables("Item")
dt.WriteXml("test.xml")
<?xml version="1.0" standalone="yes"?>
<Items>
<Item>
<ItemID>3</ItemID>
<ItemPrice>9</ItemPrice>
</Item>
<Item>
<ItemID>4</ItemID>
<ItemPrice>16</ItemPrice>
</Item>
<Item>
<ItemID>5</ItemID>
<ItemPrice>25</ItemPrice>
</Item>
<Item>
<ItemID>6</ItemID>
<ItemPrice>36</ItemPrice>
</Item>
<Item>
<ItemID>7</ItemID>
<ItemPrice>49</ItemPrice>
</Item>
<Item>
<ItemID>8</ItemID>
<ItemPrice>64</ItemPrice>
</Item>
<Item>
<ItemID>9</ItemID>
<ItemPrice>81</ItemPrice>
</Item>
<Item>
<ItemID>10</ItemID>
<ItemPrice>100</ItemPrice>
</Item>
</Items>