title: How to find a specific XML tag in .NET C#
body: <p>Suppose I have this XML file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;config&gt;
    &lt;atag&gt;
      &lt;element1 att="value" /&gt;
      &lt;element2 att="othervalue"/&gt;
    &lt;/atag&gt;
    &lt;othertag&gt;
      &lt;element1 att="value" /&gt;
      &lt;element2 att="othervalue"/&gt;
    &lt;/othertag&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>What is the best way to access the attribute <code>att</code> in  <code>&lt;element2&gt;</code> under <code>&lt;othertag&gt;</code>.</p>
  
  <p>I'm currently using this:</p>
  
  <pre><code>XmlDocument doc = new XmlDocument();
  String srR = SPContext.Current.Web.Url.ToString() + "config.xml";
  WebRequest refF = WebRequest.Create(srR);
  refF.Credentials = CredentialCache.DefaultCredentials;
  HttpWebResponse resFF = (HttpWebResponse)refF.GetResponse();
  doc.Load(resFF.GetResponseStream());
  XmlNodeList nodes = doc.GetElementsByTagName("othertag");
  
  XmlNode ParentNodes = nodes[0];
  foreach (XmlNode ParentNode in ParentNodes.ChildNodes) 
  {
      if (ParentNode.LocalName == "element2")
      {
          string value = ParentNode.Attributes["att"].InnerText.ToString();
      }
  }
  </code></pre>
  
  <p>It is doing the job, but I think it's too heavy, specially that I'm using it on an ashx file that is loaded whenever I change a value in a dropdown and the XML file is very large (around ~155kb).</p>
  
  <p>Is there any way to improve this?</p>