以下面的格式序列化XML文件

时间:2014-01-17 12:22:10

标签: vb.net xml-serialization

我有一个课程,我必须按以下格式序列化,我不知道我已经尝试使用谷歌搜索,但没有找到所以我需要你的专家帮助:)

    <XmlRoot("plist")> Public Class Plist

    Private _Elements() As Item = Nothing
    <XmlArray(ElementName:="Elements")> _
    Public Property Elements As Item()
        Get
            Return _Elements
        End Get
        Set(value As Item())
            _Elements = value
        End Set
    End Property

    Public Structure Item
        <XmlElement("key")> _
        Dim Key As String
        <XmlElement("value")> _
        Dim Value As String

        Public Sub New(_Key As String, _Value As String)
            Key = _Key
            Value = _Value
        End Sub
    End Structure
End Sub

并将XML输出作为

    <?xml version="1.0" encoding="UTF-8"?>
<plist xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Elements>
        <Item>
            <key>key1</key>
            <value>val</value>
        </Item>
        <Item>
            <key>key2</key>
            <value>value</value>
        </Item>
    </Elements>
</plist>

但我希望它像

    <?xml version="1.0" encoding="UTF-8"?>
<plist xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <Elements>
        <key>key1</key>
        <value>val</value>
        <key>key2</key>
        <value>value</value>
        <key>key3</key>
        <value>value</value>
    </Elements>
</plist>

任何人都可以帮助我?

  

PS:对不起,如果我错了:(

0 个答案:

没有答案