Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


removing children via Microsoft.XMLDOM

Posted on 2006-03-20
Medium Priority
Last Modified: 2012-08-14
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.  

          <more>data 1</more>
          <more>data 2</more>
          <more>data 3</more>
          <more>data 4</more>
          <more>data 5</more>
          <more>data 6</more>
          <more>data 7</more>
          <more>data 8</more>
Question by:BigMonkeyHead
LVL 52

Accepted Solution

Carl Tawn earned 1000 total points
ID: 16236660

   '// Assuming an XMLDOM object named oDom

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

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

Author Comment

ID: 16484315
Thanks - that's pretty much what I was looking for.  :)

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question