小编Cor*_*dra的帖子

将XML反序列化为对象时缺少子节点

我需要处理某些xml,无法从中反序列化对象列表.以下是xml:

<catalog>
<item>
    <id>18338517</id>
    <note label="Name ">Gear xyz</note>
    <note label="Size ">10</note>       
    <note label="Source">Store xyz</note>
    <relation weight="100">
        <type>External</type>
        <id>123</id>
        <name>Mcday</name>          
    </relation>
    <relation weight="99">
        <type>Internal</type>
        <id>234</id>
        <name>Mcnight</name>
    </relation>
</item>
    <item> ..... </item></catalog>
Run Code Online (Sandbox Code Playgroud)

以下是我的课

[XmlRoot("catalog")]
public class Catalog
{
    [XmlArray("item")]
    [XmlArrayItem("item", typeof(Item))]
    public Item[] item{ get; set; }
}

[XmlRoot("item")]
public class Item
{
    [XmlElement("id")]
    public string id { get; set; }

    [XmlArrayItem("note", typeof(Note))]
    public Note[] note { get; set; }

    [XmlArrayItem("relation", typeof(Relation))]
    public Relation[] relation { get; set; }
}

[Serializable]
public …
Run Code Online (Sandbox Code Playgroud)

.net c# xml

7
推荐指数
1
解决办法
2640
查看次数

标签 统计

.net ×1

c# ×1

xml ×1