I have to deserialize an XML document to objects and then serialize it back to XML to pass to the stored proc.
I am attaching partial code. After this , I also have to serialize
Here is the XML :
<data>
<orders>
<order>
<order_id>0</order_id>
<issue_id>4460</issue_id>
<action>add</action>
</order>
</orders>
</data>
This is the main.cs file where I call the Deserializer
public class Main
{
public void AcceptOrdersDom( string strInputXML )
{
OrderRootDeSerialize ordRoot =(OrderRootDeSerialize) DeserializeObject(typeof(OrderRootDeSerialize), strInputXML );
}
protected object DeserializeObject(Type t, string xml)
{
MemoryStream memStream = new MemoryStream();
StreamWriter writer = new StreamWriter(memStream, System.Text.Encoding.ASCII);
writer.Write(xml);
writer.Flush();
memStream.Seek(0, 0);
XmlSerializer xs = new XmlSerializer(t);
return xs.Deserialize(memStream);
}
}
And this the class type of which i have to deserialize.
namespace Sandeep.Test
{
[XmlRoot("data", IsNullable = false)]
public class OrderRootDeSerialize
{
public OrderRootDeSerialize ()
{}
[XmlArray("orders")]
[XmlArrayItem("order")]
public DeSerializeOrders[] ords ;
}
// Order Base Class
public class Orders
{
public Orders()
{}
#region Member Variables
protected int _orderId;
protected int _issueId;
protected string _action;
#endregion
#region Public Properties
public int OrderId
{
get { return _orderId; }
set { _orderId = value ; }
}
public int IssueId
{
get { return _issueId; }
set { _issueId = value; }
}
public string Action
{
get { return _action; }
set { _action = value; }
}
}
public class DeSerializeOrders : Orders
{
public DeSerializeOrders()
{}
[XmlElement("order_id")]
new public int OrderId
{
set { base.OrderId = value ; }
}
[XmlElement("issue_id")]
new public int IssueId
{
set { base.IssueId = value; }
}
[XmlElement("action")]
new public string Action
{
get { return base.Action ; }
set { base.Action = value; }
}
}
}
It compiles fine. When I run it it gives me an error back saying
"There was an error reflecting field 'ords'."
I have been trying to figure it out but no luck . Can somebody please help me