Search code examples
vbscriptqtpxmldom

QTP - How to remove the XmlNode from the xml document?


I want remove an xml node from an xml document, but I don't know which function can be used to achieve that. Could you please tell me how to do that?

Const XMLDataFile = "C:\TestData.xml"

xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = False
xmlDoc.Load(XMLDataFile)

nodes = xmlDoc.SelectNodes("/bookstore/book/author[text()='name=admin']")

' get their names
For i = 0 To (nodes.Length - 1)
    Title = nodes(i).NodeValue
    MsgBox("The node will be deleted " & Title)

    'TODO: The expect code here

Next

Solution

  • This isn't really a QTP question, it's an XML question. Looking at MS's documentation I would say the following will probably work

    nodes(i).parentNode.removeChild nodes(i)