title: How to query default namespace with MSXML
body: <p>I have some XML:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;Project ToolsVersion="4.0"&gt;
      &lt;PropertyGroup Condition="'$(key)'=='1111'"&gt;
            &lt;Key&gt;Value&lt;/Key&gt;
      &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p><strong>Note</strong>: This isn't the actual XML i'm using, it's just prettier and shorter, and demonstrates the problem.</p>
  
  <p>Using MSXML i can query for nodes:</p>
  
  <pre><code>IXMLDOMNode node = doc.selectSingleNode("//PropertyGroup/@Condition");
  </code></pre>
  
  <p>And it works fine:</p>
  
  <blockquote>
    <p>Condition="'$(key)'=='1111'"</p>
  </blockquote>
  
  <h1>But that's not really the XML i have</h1>
  
  <p>In reality the XML i have contains a namespace declaration:</p>
  
  <blockquote>
    <p>xmlns="http://schemas.microsoft.com/developer/msbuild/2003"</p>
  </blockquote>
  
  <p>making the <strong>actual</strong> XML document:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
      &lt;PropertyGroup Condition="'$(key)'=='1111'"&gt;
            &lt;Key&gt;Value&lt;/Key&gt;
      &lt;/PropertyGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  
  <p>Now my query:</p>
  
  <pre><code>IDOMNode node = doc.selectSingleNode("//PropertyGroup/@Condition");
  </code></pre>
  
  <p>returns no matching nodes.</p>
  
  <p>How do i query the default namespace using MSXML?</p>
  
  <p><strong>Note</strong>:</p>
  
  <ul>
  <li><p>i already know <a href="https://stackoverflow.com/questions/5951628/reference-to-undeclared-namespace-prefix-when-parsing-msxml">how to query the <strong>non-default</strong> namespace in xml</a>; you use:</p>
  
  <pre><code>   doc.setProperty("SelectionNamespaces", 
           "xmlns="http://schemas.microsoft.com/developer/msbuild/2003");
  </code></pre></li>
  <li><p>i already know <a href="https://stackoverflow.com/questions/14698271/which-namespace-is-necessary-to-use-selectsinglenode-method-using-default-nam">how to query the default namespace in .NET</a>. You use the namespace manager, give the default namespace a name, then query using that name, then you can query the non-default namespace since it's no longer default</p></li>
  <li><p>i <strong>can</strong> just delete the offensive <code>xmlns</code> text from the XML string i receive, but i'd rather "do it the right way"</p></li>
  </ul>
  
  <p>How do i query the <em>"default"</em>, or <em>"unnamed"</em> namespace using MSXML?</p>
  
  <hr>
  
  <p><strong>Note</strong>: In reality the XML i am using the SQL Server's XML <strong>ShowPlan</strong> output:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-16" standalone="yes"?&gt;
     &lt;ShowPlanXML Version="1.1" Build="10.50.1600.1" 
                     xmlns="http://schemas.microsoft.com/sqlserver/2004/07/showplan"&gt;
        &lt;BatchSequence&gt;
             &lt;Batch&gt;
             ...
             &lt;/Batch&gt;
        &lt;/BatchSequence&gt;
     &lt;/ShowPlanXML&gt; 
  </code></pre>
  
  <p>Again you can see the offending namespace declaration. Deleting it works, but that's tedious.</p>
  
  <h1>What else have you tried?</h1>
  
  <p>i also tried setting the <strong>SelectionNamespace</strong>:</p>
  
  <pre><code>doc.setProperty('SelectionNamespaces', 
        'xmlns="http://schemas.microsoft.com/developer/msbuild/2003"');
  </code></pre>
  
  <p>as <a href="http://support.microsoft.com/kb/313372" rel="nofollow noreferrer">Microsoft hints at in a KB article</a>.</p>
  
  <h1>How do i <strong>get</strong> the default namespace?</h1>
  
  <p>In reality i don't <em>care</em> about namespaces. My query makes sense, and i want it to work. So, Another approach to the question might be:</p>
  
  <blockquote>
    <p>How can i query the default namespace whether, or not, and no matter what, that namespace name is (or isn't)?</p>
  </blockquote>
  
  <p><strong>Note</strong>: msxml is <em>native</em> code, and using it from a native Win32 compiler (i.e. no .NET framework or CLR)</p>