Deserializing XML File with multiple element attributes – attributes are not deserializing

To do that you need two levels:

[XmlRoot("TestXML")]
public class TestXml {
    [XmlElement("TestElement")]
    public TestElement TestElement { get; set; }
}

public class TestElement {
    [XmlText]
    public int Value {get;set;}

    [XmlAttribute]
    public string attr1 {get;set;}

    [XmlAttribute]
    public string attr2 {get;set;}
}

Note that the > 26 < may cause problems too (whitespace); you may need that to be a string instead of an int.

Leave a Comment