Fylix
Fylix

Reputation: 2713

XML Serializer returns null for my XML attribute values

I post this in hoping a second set of eyes will help point out my error. I think I'm just overlook a simple thing here. Basically I keep getting Null value back for ExcelName and MV_Variable when I read the xml file into memory. I got other values File, Name fine.

enter image description here

enter image description here

<?xml version="1.0" encoding="utf-8" ?>
<ExcelConfig File="C:\shs\Integrations\ExcelQuery\cfg.xlsx">
  <ExcelSheet Name ="ExcelFormat">
     <Query>
        <Parameter ExcelName="Name" MV_Variable="AreaName"/>
        <Parameter ExcelName="Age" MV_Variable="ZoneName"/>
     </Query>
     <Result>
        <Parameter ExcelName ="Name" MV_Variable ="AreaName"/>
        <Parameter ExcelName="City" MV_Variable="AssetName"/>
     </Result>
  </ExcelSheet>
</ExcelConfig>



public class ExcelConfig
{
    [XmlAttribute]
    public string File { get; set; }

    [XmlElement]
    public List<ExcelSheet> ExcelSheet = new List<ExcelSheet>();
}

public class ExcelSheet
{

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

    [XmlElement]
    public List<Parameter> Query = new List<Parameter>();

    [XmlElement]
    public List<Parameter> Result = new List<Parameter>();

}

public class Parameter
{
    [XmlAttribute]
    public string ExcelName { get; set; }

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

}

Upvotes: 0

Views: 366

Answers (1)

L.B
L.B

Reputation: 116098

Change ExcelSheet as follows

public class ExcelSheet
{

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

    [XmlArray]
    public List<Parameter> Query = new List<Parameter>();

    [XmlArray]
    public List<Parameter> Result = new List<Parameter>();
}

Upvotes: 1

Related Questions