Deleting all children of an XML node

Hi everyone,

I am using VBA for MS office. I would like to know how I can delete all children of a node. The method should not fail if the node has no children.

So, basically I have:

Dim xmlParser as Object
Set xmlParser = CreateObject("MSXML2.DOMDocument")
xmlParser.LoadXML (documentXMLData)
Dim serializedElment as Object
Set serializedElement = xmlParser.ChildNodes(0).selectSingleNode("SerializedData")

Now I want to delete all children (if any) of the serializedElement node.

How can I do this?

Thanx!

Xargon
xargon_123Asked:
Who is Participating?
 
fds_fatboyConnect With a Mentor Commented:
Private Sub delChildren(element  As object)
    If element Is Nothing Then Exit Sub
    Do Until element.childNodes(0) Is Nothing
        element.removeChild element.childNodes(0)
    Loop
End Sub
0
 
fds_fatboyCommented:
Private Sub delChildren(tvw As TreeView, nod As Node)
    If nod Is Nothing Then Exit Sub
    Do Until nod.Child Is Nothing
        tvw.Nodes.Remove nod.Child.Index
    Loop
End Sub
0
 
fds_fatboyCommented:
Whoops wrong answer
0
 
fds_fatboyCommented:
And you would call it like this:

    delChildren serializedElement


Is there any reason you are doing all this using late-binding. Early binding would be more efficient and you would get the added help of being able to use intellisense.

Also I asked a question regarding a previous PAQ that you accepted from me and would appreciate an answer:
http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21394627.html
0
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.

All Courses

From novice to tech pro — start learning today.