title: Deleting an XML DOM node deletes all its siblings
body: <p>I have to prune an XML document by deleting some nodes. To do that, I have the following VBA function that is called with</p>
  
  <ul>
  <li>lists = XMLOutput.documentelement</li>
  <li>tagfound = complete path (//Header/Element/Sub-Element/...)</li>
  </ul>
  
  <p>Here is the code:</p>
  
  <pre><code>Function RemoveNode(lists, tagfound)
      Dim nodefound As Object
      Set nodefound = lists.selectSingleNode(tagfound)
      If nodefound Is Nothing Then Exit Function
      nodeToBeRemoved = nodefound.basename
      Set x = nodefound.parentnode
      For Each listnode In x.childnodes
          If listnode.basename = nodeToBeRemoved Then
              x.removechild (listnode)
          End If
      Next listnode
  End Function
  </code></pre>
  
  <p>I have tried other solutions, more elegant, like a single line of code, but ALL lead to the same result: If I have to remove a child which is the last child of its parent, all its siblings are removed as well. I tried to save the document after any removal, with no results.
  Any hints?
  To make it more clear, what follows is my input. For each XML tag, a boolean tells me if I have to keep it or to remove it from the XML tree.</p>
  
  <p>XMLTag   ToBeCoded
     Header   TRUE
     Header/Organisation  TRUE
     Header/Organisation/BaseData TRUE
     Header/Organisation/BaseData/VAT TRUE
     Header/Organisation/BaseData/VAT/Country TRUE
     Header/Organisation/BaseData/VAT/Code    TRUE
     Header/Organisation/BaseData/SocialSecurity  FALSE
     Header/Organisation/BaseData/PersonalData    TRUE
     Header/Organisation/BaseData/PersonalData/OrganisationName   TRUE
     Header/Organisation/BaseData/PersonalData/PersonalName   FALSE
     Header/Organisation/BaseData/PersonalData/FamilyName FALSE
     Header/Organisation/BaseData/PersonalData/Title  FALSE
     Header/Organisation/BaseData/PersonalData/Code   FALSE
     Header/Organisation/BaseData/ProfessionalLedger  FALSE
     Header/Organisation/BaseData/ContyOfLedger   FALSE
     Header/Organisation/BaseData/EnrollmentNumber    FALSE
     Header/Organisation/BaseData/Date    FALSE
     Header/Organisation/BaseData/IRSType FALSE
     Header/Organisation/Location TRUE
     Header/Organisation/Location/Address TRUE
     Header/Organisation/Location/StreetNumber    TRUE
     Header/Organisation/Location/ZIP TRUE
     Header/Organisation/Location/City    TRUE
     Header/Organisation/Location/County  TRUE
     Header/Organisation/Location/Country TRUE</p>
  
  <p>..and this is what I get:</p>
  
  <pre><code>&lt;Header&gt;
  &lt;Organisation&gt;
     &lt;BaseData&gt;
     &lt;VAT&gt;&lt;/VAT&gt;
       &lt;PersonalData&gt;
       &lt;/PersonalData&gt;
    &lt;/BaseData&gt;
    &lt;Location&gt;
      &lt;Address&gt;any street name&lt;/Address&gt;
      &lt;StreetNumber&gt;any street number&lt;/StreetNumber&gt;
      &lt;ZIP&gt;any ZIP code&lt;/ZIP&gt;
      &lt;City&gt;any City&lt;/City&gt;
      &lt;County&gt;any County&lt;/County&gt;
      &lt;Country&gt;any Country&lt;/Country&gt;
     &lt;/Location&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>It is easy to see that I do not get any fields for the tag PersonalData, while I should have removed all children except OrganisationName, which happens to be the first child. Also, BaseData/VAT/Country and BaseData/VAT/Code are not there (the VAT parent is there, but empty).</p>