please try to use the code below, the ParseXML/XMLFile.xml is the file where ive pasted the content of your xml:
XDocument doc = XDocument.Load(Server.MapPath("~/ParseXML/XMLFile.xml"));
List<SRADBData> objList = new List<SRADBData>();
var listMain = doc.Elements("TRR").Elements("Detail");
foreach (XElement xll in listMain)
{
if (string.Compare(xll.Name.ToString(), "Detail", true) == 0)
{
SRADBData objSRA = new SRADBData();
Segment objSeg = new Segment();
if (xll.Elements("Segment") != null)
{
objSeg.orgin = xll.Element("Segment").Element("Orgin").Value.ToString();
objSeg.segmentId = Convert.ToInt32(xll.Element("Segment").Element("SegmentId").Value);
}
objSRA.originProduct = xll.Element("OriginProduct").Value.ToString();
objSRA.routeId = Convert.ToInt32(xll.Element("RouteId").Value);
objSRA.toDate = Convert.ToDateTime(xll.Element("ToDate").Value);
objSRA.segment = objSeg;
objList.Add(objSRA);
}
}
but before using it make sure you've used these namespaces:
using System.Linq;
using System.Xml.Linq;
Ashutosh Pathak
Blog: http://catchcode.blogspot.com Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS
Ashutosh Pat...
Contributor
5737 Points
1105 Posts
Re: How to handle Storedprocedure in c# which return xml data.
Mar 28, 2012 06:11 AM|LINK
please try to use the code below, the ParseXML/XMLFile.xml is the file where ive pasted the content of your xml:
XDocument doc = XDocument.Load(Server.MapPath("~/ParseXML/XMLFile.xml")); List<SRADBData> objList = new List<SRADBData>(); var listMain = doc.Elements("TRR").Elements("Detail"); foreach (XElement xll in listMain) { if (string.Compare(xll.Name.ToString(), "Detail", true) == 0) { SRADBData objSRA = new SRADBData(); Segment objSeg = new Segment(); if (xll.Elements("Segment") != null) { objSeg.orgin = xll.Element("Segment").Element("Orgin").Value.ToString(); objSeg.segmentId = Convert.ToInt32(xll.Element("Segment").Element("SegmentId").Value); } objSRA.originProduct = xll.Element("OriginProduct").Value.ToString(); objSRA.routeId = Convert.ToInt32(xll.Element("RouteId").Value); objSRA.toDate = Convert.ToDateTime(xll.Element("ToDate").Value); objSRA.segment = objSeg; objList.Add(objSRA); } }but before using it make sure you've used these namespaces:
Blog: http://catchcode.blogspot.com
Please mark it as answer if it helps, as clicking on the button can save time of others :)
MCP,MCAD,MCSD,MCTS