title: Linq2XML, Why isn't Element(), Elements() working?
body: <p>I am trying to traverse through a simple sitemap (adding and deleting elements on the fly.) This is the sample layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;urlset
        xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
              http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"&gt;
    &lt;url&gt;
      &lt;loc&gt;http://mysite.com/&lt;/loc&gt;
      &lt;priority&gt;1.00&lt;/priority&gt;
      &lt;changefreq&gt;daily&lt;/changefreq&gt;
    &lt;/url&gt;
    &lt;url&gt;
      &lt;loc&gt;http://mysite.com/Default.aspx&lt;/loc&gt;
      &lt;priority&gt;0.80&lt;/priority&gt;
      &lt;changefreq&gt;daily&lt;/changefreq&gt;
    &lt;/url&gt;
  &lt;/urlset&gt;
  </code></pre>
  
  <p>Weirdly when I try to access a child element using the Element() method after loading the document, it's null, and so is Elements(), so I can't traverse through them. The Nodes() method has the elements though. </p>
  
  <p>Here's the code I wrote</p>
  
  <pre><code>XElement siteMap = XElement.Load(Server.MapPath("~/sitemap.xml"));
  
  //First remove all article nodes
  foreach (XElement elem in siteMap.Elements())
  {
      XElement loc = elem.Element("loc");
      if (loc.Value.Contains("http://mysite.com/articles/"))
          elem.Remove();
  }
  </code></pre>
  
  <p>No matter what I do to try and retrieve the elements of elem (Element, Elements), I get a null.</p>
  
  <p>What could be wrong? This code is supposed to run. Isn't it?</p>