Thursday, March 03, 2011

Here is a quick reference on using XDocument

Here is a quick reference on using XDocument


5


1) Loading an XML file into a Xdocument object

XDocument xdocSource = XDocument.Parse(Xmltmp);

2) Loading a string directly into a Xdocument object

XDocument xdocSource = XDocument.Load(XMLReader xr);

3) To get to a particular element you need to follow the path

XmlElement xe = xdocSource.Descendants(soap + "JobDetails").FirstOrDefault().Element(soap + "JobNumber");

4) To get the value of the above use the following
string tmp = xdocSource.Descendants(soap + "JobDetails").FirstOrDefault().Element(soap + "JobNumber").Value;


No comments: