Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Old question but I think that lot of people have this problem, like I did.</p> <p>The xmlns stand for: XML NameSpace. So, when it is in present in the XML you need to use it to search. For example, if you want to find an element like <code>"&lt;url xmlns='sm'&gt;"</code>, you would need to especify that you're looking for an element that has name <code>"url"</code> and namespace <code>"sm"</code>.</p> <p>Why? I'm sorry I can't answer exactly why, but it works like this.</p> <p>Well, to solve my problem I've changed my code to use XmlReader and LinqToXML, what make things "much easier".</p> <p>This is the XML:</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt; &lt;url&gt; &lt;loc&gt;http://www.url.com/&lt;/loc&gt; &lt;changefreq&gt;daily&lt;/changefreq&gt; &lt;priority&gt;1.00&lt;/priority&gt; &lt;/url&gt; &lt;url&gt; &lt;loc&gt;http://www.url.com/&lt;/loc&gt; &lt;changefreq&gt;daily&lt;/changefreq&gt; &lt;priority&gt;0.9000&lt;/priority&gt; &lt;/url&gt; &lt;url&gt; &lt;loc&gt;http://www.url.com/&lt;/loc&gt; &lt;changefreq&gt;daily&lt;/changefreq&gt; &lt;priority&gt;0.9000&lt;/priority&gt; &lt;/url&gt; &lt;url&gt; &lt;loc&gt;http://www.url.com/&lt;/loc&gt; &lt;changefreq&gt;daily&lt;/changefreq&gt; &lt;priority&gt;0.9000&lt;/priority&gt; &lt;/url&gt; &lt;/urlset&gt; </code></pre> <p>And this is the code that I used to read it:</p> <pre><code> XDocument xmlDoc = XDocument.Load("sitemap.xml"); if (xmlDoc.Elements().Count() &gt; 0) { using (MemoryStream memStream = new MemoryStream()) { xmlDoc.Save(memStream); memStream.Position = 0; using (XmlReader reader = XmlReader.Create("sitemap.xml", new XmlReaderSettings() { IgnoreWhitespace = true })) { reader.MoveToContent(); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element &amp;&amp; reader.LocalName.Equals("url", StringComparison.OrdinalIgnoreCase)) { XElement el = XNode.ReadFrom(reader) as XElement; if (el == null) continue; XName loc = XName.Get("loc", el.Name.Namespace.NamespaceName); XName changefreq = XName.Get("changefreq", el.Name.Namespace.NamespaceName); XName priority = XName.Get("priority", el.Name.Namespace.NamespaceName); var elLoc = el.Element(loc); var elChangeFreq = el.Element(changefreq); var elPriority = el.Element(priority); } } } } } </code></pre> <p>Hope this helps. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload