[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 696
  • Last Modified:

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
0
xargon_123
Asked:
xargon_123
  • 4
1 Solution
 
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:
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:
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

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.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now