Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 指定值的XMLElement的XML反序列化_C#_Xml_Deserialization - Fatal编程技术网

C# 指定值的XMLElement的XML反序列化

C# 指定值的XMLElement的XML反序列化,c#,xml,deserialization,C#,Xml,Deserialization,我相信这很简单,但我找不到答案。对于XML文件的这一部分,正确的类语法是什么 我已经走了这么远,但似乎遗漏了什么,请原谅我的双关语,钥匙!我觉得我用了错误的方法来处理它,但是我似乎找不到一个与元素中包含值的XML匹配的示例代码 [Serializable, XmlRoot("Keys")] public class Keys { [XmlElement("Key")] public Key Key { get; set; }

我相信这很简单,但我找不到答案。对于XML文件的这一部分,正确的类语法是什么

我已经走了这么远,但似乎遗漏了什么,请原谅我的双关语,钥匙!我觉得我用了错误的方法来处理它,但是我似乎找不到一个与元素中包含值的XML匹配的示例代码

        [Serializable, XmlRoot("Keys")]
    public class Keys
    {
        [XmlElement("Key")]
        public Key Key { get; set; }          
    }

    [Serializable, XmlRoot("Key")]
    public class Key
    {
        [XmlAttribute("TYPE")]
        public string Type { get; set; } 

    }

我想您正在寻找XmlTextAttribute,它将为您提供号码。另外,我认为您需要一个密钥集合,在这种情况下,我们需要将其声明为集合

[XmlRoot("Keys")]
public class Keys
{
    [XmlElement("Key")]
    public List<Key> Items { get; set; }          
}

public class Key
{
    [XmlAttribute("TYPE")]
    public string Type { get; set; } 

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

非常感谢泰,太完美了,非常感谢!
public class MyObject
{
    [XmlArray("Keys")]
    [XmlArrayItem("Key")]
    public List<Key> Keys {get;set;}
}

public class Key
{
    [XmlAttribute("TYPE")]
    public string Type { get; set; } 

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