removing children via Microsoft.XMLDOM

I'm creating an XML doc with the Microsoft.XMLDOM object.  As I work my way thru the building doc, I create <level1Child> nodes (per the example below).  Then I create <sample> nodes, and finally <more> nodes.  If the data for the <more> nodes does not meet a certain criteria, I don't need to add the <more> node.  Due to the nature of my code, I've already added the <level1Child> node and the <sample> node.

The problem is, sometimes after working my way thru, I may have some <level1Child> nodes that do not have any <more> nodes underneath them - see the 2nd <level1Child> as an example.  I need a quick-n-dirty way to look at the document once I'm done building it, and examine it to see which <level1Child> nodes do not have any <more> nodes underneath them.  For each one that doesn't, I need to remove that node and any <sample> nodes.  

<root>
  <level1>
     <level1Child>
        <sample>
          <more>data 1</more>
          <more>data 2</more>
          <more>data 3</more>
        </sample>
        <sample>
          <more>data 4</more>
          <more>data 5</more>
        </sample>
        <sample>
          <more>data 6</more>
        </sample>
     </level1Child>
     <level1Child>
       <sample/>
     </level1Child>
     <level1Child>
         <sample>
          <more>data 7</more>
          <more>data 8</more>
        </sample>
     </level1Child>
  </level1>
</root>
LVL 1
BigMonkeyHeadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:

   '// Assuming an XMLDOM object named oDom

    Set oNodes = oDom.selectNodes("//level1Child[count(sample/more)=0]")
    For Each node In oNodes
       node.parentNode.RemoveChild node
    Next


This might not be 100% cos i'm doing it from memory :o)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BigMonkeyHeadAuthor Commented:
Thanks - that's pretty much what I was looking for.  :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.