Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Deserialize this Xml file?

I have this Xml file, and I need to Deserialize it back to a class. The problem is: what is the right structure/design of this class considering that the count of the Xml element (RowInfo) is not constant? The Xml File:

<?xml version="1.0"?>
<SomeObject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <Layers>   
 <Layer Id="0">
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,0,0,1,1,1</RowInfo>
      <RowInfo>1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1</RowInfo>
      <RowInfo>1,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,1,0,0,1</RowInfo>
      <RowInfo>1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1</RowInfo>
    </Layer>
  </Layers>   
</SomeObject>

Appreciate your help. Thanks.

Edit1:also considering that (Layers) may contains more than one layer.

like image 894
Robin-Hood Avatar asked Feb 24 '23 23:02

Robin-Hood


1 Answers

Something like the following - names will need to be changed to protect the innocent:

Class structure after comment

public class SomeObject 
{
  public List<Layer> Layers {get;set;}
}

public class Layer
{
  public int Id {get;set;}
  public List<RowInfo> RowInfos {get;set;}
}

public class RowInfo
{
  public List<Row> Rows {get;set;}
}

public class Row
{
  public int RowData {get;set;}
}
like image 110
amelvin Avatar answered Mar 08 '23 14:03

amelvin