You can use
XmlDocument class to extract the values in to a datatable.
Sample Code:
DataTable table1 = new DataTable("dt1");
//Add columns
DataColumn column1 = new DataColumn("CountryID", typeof(System.String));
DataColumn column2 = new DataColumn("CountryCode", typeof(System.String));
DataColumn column3 = new DataColumn("CountryName", typeof(System.String));
table1.Columns.Add(column1);
table1.Columns.Add(column2);
table1.Columns.Add(column3);
DataRow dr = table1.NewRow();
XmlDocument Doc = new XmlDocument();
//Get your response here
//Doc.LoadXml(TransportResponse.Response)
//Your Sample XML String
Doc.LoadXml(@"<soap:Envelope xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
<soap:Body>
<LBCCountriesResponse xmlns=""http://tempuri.org/"">
<LBCCountriesResult>
<LBCCountry>
<CountryID>10</CountryID>
<CountryCode>AU</CountryCode>
<CountryName>AUSTRALIA</CountryName>
</LBCCountry>
<LBCCountry>
<CountryID>38</CountryID>
<CountryCode>AT</CountryCode>
<CountryName>AUSTRIA</CountryName>
</LBCCountry>
</LBCCountriesResult>
</LBCCountriesResponse>
</soap:Body>
</soap:Envelope>");
//Create object of XMLElement
XmlElement myElement = Doc.DocumentElement;
//Get the list of LBCCountry nodes
XmlNodeList nodelist = Doc.GetElementsByTagName("LBCCountry");
//Loop throuugh each nodes
foreach (XmlNode nodes in nodelist)
{
//Create a new row in datatable
dr = table1.NewRow();
//Get the CountryID Element Value
dr["CountryID"] = nodes.ChildNodes[0].InnerText;
//Get the CountryCode Element Value
dr["CountryCode"] = nodes.ChildNodes[1].InnerText;
//Get the CountryName Element Value
dr["CountryName"] = nodes.ChildNodes[2].InnerText;
//Add the rows to datatable
table1.Rows.Add(dr);
}
Member
4 Points
24 Posts
soap response to xml and extract
Apr 11, 2014 07:55 PM|auwi987|LINK
hello guys i need some help regarding soap and how to parse it to extract data
im having pain on this guys dont know what to do
need some help guys many thanks
soap xml csharp
All-Star
50831 Points
9895 Posts
Re: soap response to xml and extract
Apr 12, 2014 02:43 AM|A2H|LINK
You can use XmlDocument class to extract the values in to a datatable.
Sample Code:
soap xml csharp
Aje
My Blog | Dotnet Funda
Contributor
2801 Points
708 Posts
Re: soap response to xml and extract
Apr 12, 2014 03:03 AM|itsmemuthu|LINK
soap xml csharp
Remember To Click On the Post That Helps U