title: Ignoring supplied namespaces when validating XML with XSD
body: <p><strong>Background:</strong></p>
  
  <p>We're building an application that allows our customers to supply data in a predefined (ie. we don't control) XML format.  The XSD is supplied to us by a Third Party, and we are expecting to receive an XML file that passes schema validation prior to us processing it.</p>
  
  <p><strong>The Problem:</strong></p>
  
  <p>The XSD that we are supplied with includes a default and target namespace, which means that if a customer supplies an XML file that doesn't include the namespace, then the validation will pass.  We obviously don't want them to be supplying things that say they pass but shouldn't, but the bigger concern is around the mass of additional checks that we will need to do on each element if I can't find a solution to doing the XML validation.</p>
  
  <p><strong>The Questions:</strong></p>
  
  <p>Is it possible to force .NET to perform validation and ignore the namespace on the supplied XML and XSD.  i.e. in some way "assume" that the namespace was attached.</p>
  
  <ol>
  <li>Is it possible to remove the namespaces in memory, easily, and reliably?</li>
  <li>What is the best practice in these situations?</li>
  </ol>
  
  <p><strong>Solutions that I have so far:</strong></p>
  
  <ol>
  <li>Remove the namespace from the XSD everytime it's updated (shouldn't be very often.
  This doesn't get around the fact that if they supply a namespace it will be still pass validation.</li>
  <li>Remove the namespace from the XSD, AND find a way to strip the namespace from the incoming XML everytime.  This seems like a lot of code to perform something simple.</li>
  <li>Does some pre-qualification on the XML file before it validated to ensure that it has the correct namespace.  Seems wrong to fail them due to an invalid namespace if the contents of the file are correct.</li>
  <li>Create a duplicate XSD that doesn't have a namespace, however if they just supply the wrong namespace, or a different namespace, then it will still pass.</li>
  </ol>
  
  <p><strong>Example Xml:</strong></p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xsd:schema version='3.09' elementFormDefault='qualified' attributeFormDefault='unqualified' id='blah' targetNamespace='urn:schemas-blah.com:blahExample' xmlns='urn:blah:blahExample' xmlns:xsd='http://www.w3.org/2001/XMLSchema'&gt;
  ...
  &lt;/xsd:schema&gt;
  </code></pre>
  
  <p>with namespace that is different</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  &lt;root xmlns="urn:myCompany.com:blahExample1" attr1="2001-03-03" attr2="google" &gt;
  ...
  &lt;/root&gt;
  </code></pre>
  
  <p>without namespace at all.</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8" ?&gt; 
  &lt;root attr1="2001-03-03" attr2="google" &gt;
  ...
  &lt;/root&gt;
  </code></pre>