Dev Shed Forums - C Programming http://forums.devshed.com/ C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems. You can also talk about C# implementation in our .NET section below, when applicable. en Wed, 19 Jun 2019 16:42:13 GMT vBulletin 60 http://forums.devshed.com/images/misc/rss.png Dev Shed Forums - C Programming http://forums.devshed.com/ Array http://forums.devshed.com/programming/981584-array-new-post.html Thu, 06 Jun 2019 04:57:06 GMT What is Jagged array in c#? What is Jagged array in c#? ]]> C Programming AjayGohil http://forums.devshed.com/programming-42/array-981584.html <![CDATA[List<T> not deserialize xml in C#]]> http://forums.devshed.com/programming/981572-list-deserialize-xml-new-post.html Mon, 03 Jun 2019 09:24:16 GMT type. But when i try to deserialize it below code is not able to deserialize the XML and i am not getting List value. I am providing the code i have tried, XML and Class for XML. Code XmlSerializer serializer = new XmlSerializer(typeof(ECFindOrderResponse.Envelope)); using (TextReader...]]> I have a xml and for deserialize it I created a class with List<Order> type. But when i try to deserialize it below code is not able to deserialize the XML and i am not getting List<Order> value.

I am providing the code i have tried, XML and Class for XML.

Code

XmlSerializer serializer = new XmlSerializer(typeof(ECFindOrderResponse.Envelope));
using (TextReader reader = new StringReader(str))
{
if (reader != null)
{
ECFindOrderResponse.Envelope result = (ECFindOrderResponse.Envelope)serializer.Deserialize(reader);
if (result != null && result.Body != null)
{

}
}
}

My expected XML as a response that i want to deserialize

<?xml version="1.0" encoding="UTF-8"?>
<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP:Body>
<m:FindOrderResponse xmlns:m="http://www.courier.com/schemas/">
<Orders>
<Order OrderID="9653653" OrderNumber="9653653" Auth="19204071" Service="NAT-Other" AmountCharged="96.39" PodName="Tina Sample" PodDateTime="10/8/2016 10:19:00 AM" OrderDate="10/8/2016">
<Stops>
<Stop Sequence="1" Name="United Airlines" Address="AWB#016-9672-4071" City="LOUISVILLE" State="KY" Zip="40213" DispatchZone="40213" />
<Stop Sequence="2" Name="Tina Sample" Address="6300 Aurora Ave" City="Charlestown" State="IN" Zip="47111" DispatchZone="47111" />
</Stops>
</Order>
<Order OrderID="9653653" OrderNumber="9653653" Auth="19204071" Service="NAT-Other" AmountCharged="96.39" PodName="Tina Sample" PodDateTime="10/8/2016 10:19:00 AM" OrderDate="10/8/2016">
<Stops>
<Stop Sequence="1" Name="United Airlines" Address="AWB#016-9672-4071" City="LOUISVILLE" State="KY" Zip="40213" DispatchZone="40213" />
<Stop Sequence="2" Name="Tina Sample" Address="6300 Aurora Ave" City="Charlestown" State="IN" Zip="47111" DispatchZone="47111" />
</Stops>
</Order>
</Orders>
</m:FindOrderResponse>
</SOAP:Body>
</SOAP:Envelope>


C# Class file

public class ECFindOrderResponse
{
[XmlRoot(ElementName = "Stop")]
public class Stop
{
[XmlAttribute(AttributeName = "Sequence")]
public string Sequence { get; set; }
[XmlAttribute(AttributeName = "Name")]
public string Name { get; set; }
[XmlAttribute(AttributeName = "Address")]
public string Address { get; set; }
[XmlAttribute(AttributeName = "City")]
public string City { get; set; }
[XmlAttribute(AttributeName = "State")]
public string State { get; set; }
[XmlAttribute(AttributeName = "Zip")]
public string Zip { get; set; }
[XmlAttribute(AttributeName = "DispatchZone")]
public string DispatchZone { get; set; }
}

[XmlRoot(ElementName = "Stops")]
public class Stops
{
[XmlElement(ElementName = "Stop")]
public List<Stop> Stop { get; set; }
}

[XmlRoot(ElementName = "Order")]
public class Order
{
[XmlElement(ElementName = "Stops")]
public Stops Stops { get; set; }
[XmlAttribute(AttributeName = "OrderID")]
public string OrderID { get; set; }
[XmlAttribute(AttributeName = "OrderNumber")]
public string OrderNumber { get; set; }
[XmlAttribute(AttributeName = "Auth")]
public string Auth { get; set; }
[XmlAttribute(AttributeName = "Service")]
public string Service { get; set; }
[XmlAttribute(AttributeName = "AmountCharged")]
public string AmountCharged { get; set; }
[XmlAttribute(AttributeName = "PodName")]
public string PodName { get; set; }
[XmlAttribute(AttributeName = "PodDateTime")]
public string PodDateTime { get; set; }
[XmlAttribute(AttributeName = "OrderDate")]
public string OrderDate { get; set; }
}

[XmlRoot(ElementName = "Orders")]
public class Orders
{
[XmlElement(ElementName = "Order")]
public List<Order> Order { get; set; }
}

[XmlRoot(ElementName = "FindOrderResponse", Namespace = "http://www.courier.com/schemas/")]
public class FindOrderResponse
{
[XmlElement(ElementName = "Orders")]
public Orders Orders { get; set; }
[XmlAttribute(AttributeName = "m", Namespace = "http://www.w3.org/2000/xmlns/")]
public string M { get; set; }
}

[XmlRoot(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Body
{
[XmlElement(ElementName = "FindOrderResponse", Namespace = "http://www.e-courier.com/schemas/")]
public FindOrderResponse FindOrderResponse { get; set; }
}

[XmlRoot(ElementName = "Envelope", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public class Envelope
{
[XmlElement(ElementName = "Body", Namespace = "http://schemas.xmlsoap.org/soap/envelope/")]
public Body Body { get; set; }
[XmlAttribute(AttributeName = "SOAP", Namespace = "http://www.w3.org/2000/xmlns/")]
public string SOAP { get; set; }
}
} ]]>
C Programming Rushabh Verma http://forums.devshed.com/programming-42/list-deserialize-xml-981572.html
C Programming http://forums.devshed.com/programming/981566-programming-new-post.html Fri, 31 May 2019 06:59:56 GMT Hello All, I am totally confused about C programming where i can start to learn it. I have seen so many online resources to learn it but still, I am confused. I want to free resource to learn it with real time example. Can anyone know that resource? Hello All, I am totally confused about C programming where i can start to learn it. I have seen so many online resources to learn it but still, I am confused. I want to free resource to learn it with real time example. Can anyone know that resource? ]]> C Programming arjunkumar http://forums.devshed.com/programming-42/programming-981566.html