WannabeNerd
asked on
Deserialization XMl file
I am writing c# classes to deserialize xml file.
I am not able to write a class for the part below :
The problem is that OrderLine exists more then once and i want to deserialize order line to an array or something.
Any help will be appreciated
************************** ********** ********** ********** **
<ORDER>
<OrderLine>
<LineNumber>1</LineNumber>
<Product>
<SuppliersProductCode/>
<BuyersProductCode>xxxx</B uyersProdu ctCode>
<Description>xxxx7</Descri ption>
</Product>
<Quantity>
<Packsize>EACH</Packsize>
<Amount>3</Amount>
</Quantity>
</Delivery>
</OrderLine>
<OrderLine>
<LineNumber>2</LineNumber>
<Product>
<SuppliersProductCode/>
<BuyersProductCode>xxxx</B uyersProdu ctCode>
<Description>xxxx7</Descri ption>
</Product>
<Quantity>
<Packsize>EACH</Packsize>
<Amount>3</Amount>
</Quantity>
</Delivery>
</OrderLine>
</ORDER>
I am not able to write a class for the part below :
The problem is that OrderLine exists more then once and i want to deserialize order line to an array or something.
Any help will be appreciated
**************************
<ORDER>
<OrderLine>
<LineNumber>1</LineNumber>
<Product>
<SuppliersProductCode/>
<BuyersProductCode>xxxx</B
<Description>xxxx7</Descri
</Product>
<Quantity>
<Packsize>EACH</Packsize>
<Amount>3</Amount>
</Quantity>
</Delivery>
</OrderLine>
<OrderLine>
<LineNumber>2</LineNumber>
<Product>
<SuppliersProductCode/>
<BuyersProductCode>xxxx</B
<Description>xxxx7</Descri
</Product>
<Quantity>
<Packsize>EACH</Packsize>
<Amount>3</Amount>
</Quantity>
</Delivery>
</OrderLine>
</ORDER>
public class Order
{
public OrderLine OrderLine;
}
public class OrderLine
{
private int _LineNumber;
private Product _Product;
private Quantity _Quantity;
public int LineNumber
{
set { _LineNumber = value; }
get { return _LineNumber; }
}
public Product Product
{
set { _Product = value; }
get { return _Product; }
}
public Quantity Quantity
{
set { _Quantity = value; }
get { return _Quantity; }
}
}
public class Product
{
private string _BuyersProductCode;
private string _Description;
public string BuyersProductCode
{
set { _BuyersProductCode = value; }
get { return _BuyersProductCode; }
}
public string Description
{
set { _Description = value; }
get { return _Description; }
}
}
public class Quantity
{
private int _Amount;
public int Amount
{
set { _Amount = value; }
get { return _Amount; }
}
}
Some nasty errors in there, this version is better.
public class Order
{
private List<OrderLine> _orderLineList = new List<OrderLine>();
public void AddOrderLine(OrderLine orderLine)
{
this._orderLineList.Insert(orderLine.LineNumber,orderLine)
}
public Order GetOrderLine(int index)
{
return this._orderLineList[index]);
}
//add other accessor/modifier methods as appropriate
}
This is what happens when answering questions while being on the phone ;)
public class Order
{
private List<OrderLine> _orderLineList = new List<OrderLine>();
public void AddOrderLine(OrderLine orderLine)
{
this._orderLineList.Insert(orderLine.LineNumber,orderLine)
}
public OrderLine GetOrderLine(int index)
{
return this._orderLineList[index]);
}
//add other accessor/modifier methods as appropriate
}
ASKER
well then how to deserialize it and get orderline items ?
If you are looking for a tutorial on xml deserialization in C# I'm not going to get into that myself. You can find loads of these on the web:
http://mehranikoo.net/CS/archive/2007/02/05/SerialisationAndEncodingInWCF.aspx
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.deserialize(VS.71).aspx
or someone else here might help you.
I was merely giving a suggestion in regards to your class structure based on your statement: "I am not able to write a class for the part below".
http://mehranikoo.net/CS/archive/2007/02/05/SerialisationAndEncodingInWCF.aspx
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.deserialize(VS.71).aspx
or someone else here might help you.
I was merely giving a suggestion in regards to your class structure based on your statement: "I am not able to write a class for the part below".
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window