C# xml内联数组反序列化

标签 c# xml

像这样反序列化 xml 的最简单方法是什么:

<root>
    <item id="1"/>
    <item id="2"/>
    <item id="3"/>
</root>

最佳答案

实际上,这是可能的-答案here显示如何。只需将属性定义为数组,但使用 XmlElement

进行注释
public class Item
{
    [XmlAttribute("id")]
    public int Id { get ;set; }

    [XmlText]
    public string Name { get; set; }
}

[XmlRoot("root")]
public class Root
{
    [XmlElement("item")]
    public Item[] Items { get;set;}
}

关于C# xml内联数组反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14768918/

相关文章:

c# - 带有代码修复模板的分析器

c# - 在 BluePrism 中引用 Office 互操作对象

php - 选择要从 XML 导入到 mySQL 表的数据

xml - Delphi 7 与 XML 通信

android - 如何创建这个切换按钮?

c# - 等同于 asp.net-core 中的 AntiForgery.Validate() 的命令

c# - 如何使用 redis 字典添加 IEnumerable< T > 集合数据?

c# - 如何仅匹配正则表达式中的第一个数字

c# - 将 XML 发布到 URL

html - XPath选择文本,但某些部分除外