How to get element by element from XmlDocument

I was able to get my first element from this list

 <?xml version="1.0" encoding="utf-8"?>
<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>
    <GetITARListResponse xmlns="http://tempuri.org/">
      <GetITARListResult>
        <ClassificationCode>
          <code>dsd</code>
          <description>toto</description>
          <legislation>d/legislation>
        </ClassificationCode>
        <ClassificationCode>
          <code>dsd</code>
          <description>tata</description>
          <legislation>dsd</legislation>
        </ClassificationCode>
        <ClassificationCode>
          <code>code2</code>
          <description>dsds</description>
          <legislation>dsd</legislation>
        </ClassificationCode>

by writing

      XDocument result = new XDocument();
       result  =   ExportControl.ResultXML;
       var codes = HttpContext.Current.Server.MapPath("~/XML_Templates/codes.xml");
dynamic root = new ExpandoObject();
XmlToDynamic.Parse(root, xDoc.Elements().First());
  var result = xDoc.Descendants(XNamespace.Get("http://tempuri.org/") + "code").First();

witch get the the first code “dsd”

but what if I want a foreach? and get all the code ?

or what if I want a certain code ? for exemple

var result = xDoc.Descendants(XNamespace.Get("http://tempuri.org/") + "code")[2]

I would appreciate a help

thanks

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s