dimanche 2 août 2015

Deserializing XML attribute 'xsi:type'

This is my first time to ask on stackoverflow and also the first time to work with xml files , so I don't think it can get worse than that. I need to deserialize some long XML but the part thats bugging me is the following:

<CastleConfigSub xmlns:xsi="http://ift.tt/ra1lAU" xsi:noNamespaceSchemaLocation="../xsd/c5c.xsd" Format="1">
  <ConfigFile Name="EdgeDetection">
    <Interfaces>
      <Interface Name="EdgeDetectionModule">
        <Doc />
         <Functions>
          <Function Name="MonitorNoChanges">
            <Doc>This Function checks that no edge has been detected at the specified                    digital channel for a specific time in msec
                1. DigitalChanelToWatch: This is the digital Input channel to monitor                      edges on it.
                2. TimeOut: This is the monitoring Period for the edges on the digitial                    input channel.
            </Doc>
            <Args>
              <Arg xsi:type="ArgEnum" Name="DigitalChanelToWatch"                                      Enum="DigitalInChannelID" />
              <Arg xsi:type="ArgValue" Name="TimeOut" EncodedType="uint32"                               Unit="msec" />
            </Args>
           </Function>
          </Functions>
        </Interface>
      </Interfaces>
    </ConfigFile>
  </CastleConfigSub>
public class CastleConfigSub
{
    [XmlElement("Options")]
    public Options options = new Options();

    [XmlElement("ConfigFile")]
    public ConfigFile configFile= new ConfigFile();


} 
public class ConfigFile
{
    [XmlElement("Doc")]
    public string doc {get; set;} 
    [XmlElement("History")]
    public History history = new History();
    [XmlElement("Includes")]
    public Includes includes = new Includes();
    [XmlElement("Options")]
    public Options options = new Options();
    [XmlElement("DataTypes")]
    public DataTypes dataTypes = new DataTypes();

    [XmlArray("Interfaces")]
    [XmlArrayItem("Interface")]
    public List<Interface> interfaces = new List<Interface>();


}
 public class Interface
{
    [XmlAttribute("Name")]
    public string name="";
    [XmlElement("Doc")]
    [XmlArray("Functions")]
    [XmlArrayItem("Function")]
    public List<Function> functions = new List<Function>();
}
public class Function
{

    [XmlAttribute("Name")]
    public string name="";
    [XmlElement("Doc")]
    public string doc="";
    [XmlArray("Args")]
    [XmlArrayItem("Arg")]
    public List<Arg> args = new List<Arg>();
}
public class Arg
{
    [XmlAttribute ("xsi:type")]
    public string type = "";
    [XmlAttribute("Name")]
    public string name ="";
    [XmlAttribute("EncodedType")]
    public string encodedType="";
    [XmlAttribute("Enum")]
    public string enumName ="";
    [XmlAttribute("Unit")]
    public string unit="";

}

I know everthing is so messy but i couldnt do any better :/.

Aucun commentaire:

Enregistrer un commentaire