title: 'xsi' is an undeclared prefix using XmlDocument
body: <p>I am receiving 'xsi' is an undeclared prefix using XmlDocument.</p>
  
  <p>I am trying to read a file which has the following schema:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;kml xmlns="http://www.opengis.net/kml/2.2"
       xmlns:gx="http://www.google.com/kml/ext/2.2" 
       xmlns:kml="http://www.opengis.net/kml/2.2"
       xmlns:atom="http://www.w3.org/2005/Atom"&gt;
          &lt;Document&gt;
              &lt;Document id="robert" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd"&gt;
                &lt;Placemark&gt;
                  &lt;description&gt;test&lt;/description&gt;
                &lt;/Placemark&gt;
          &lt;/Document&gt;
      &lt;/Document&gt;
  &lt;/kml&gt;
  </code></pre>
  
  <p>I have tried the following:</p>
  
  <pre><code>    XmlDocument xmldoc = new XmlDocument();
      using (XmlTextReader tr = new XmlTextReader(strXmlFile))
      {
          //tr.Namespaces = false; (uncomment to ignore namespace)
          xmldoc.Load(tr);  // 'xsi' is an undeclared prefix error here
      }
  </code></pre>
  
  <p>If I uncomment the line to ignore the namespace, it loads ok but fails to save the <code>XmlDocument</code> later on.  So ignoring it would not be a solution.  Does anyone know how to properly load the schema?  The issue/error appears to be in this node:</p>
  
  <pre><code>&lt;Document id="robert" xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd"&gt;
  </code></pre>
  
  <p><strong>Update #1</strong>
  I tried the following:</p>
  
  <pre><code>XmlDocument xmldoc = new XmlDocument();
  NameTable nt = new NameTable();
  XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
  nsmgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
  XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
  XmlReaderSettings xset = new XmlReaderSettings();
  xset.ConformanceLevel = ConformanceLevel.Fragment;
  XmlReader rd = XmlReader.Create(new StringReader(strXmlFile), xset, context);
  xmldoc.Load(rd);  // error is still on this line
  </code></pre>
  
  <p>But am receiving this error now:</p>
  
  <p>"The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type."  It looks like I am getting closer...</p>