RE: Remove node in xml file from Visual Basic?

Subject: RE: Remove node in xml file from Visual Basic?
From: Ben Robb <Ben@xxxxxxxxxx>
Date: Thu, 13 Apr 2000 13:41:03 +0100
It was a little off-topic, but since I know the answer, I'll post it anyway
*grin* For future reference, there is an XML Discussion list at 15seconds
(xml@xxxxxxxxxxxxxxxxxx) which would be more appropriate for this question.


I would do it something like this (basically you need to use the parentNode
method):

+++++++++++++++++++++++++
Set objNodeList = xmldoc.getElementsByTagName("gen_date")

for each datenode in objNodeList

' put in all of the date formating stuff
	If Tmp_Date = Del_Dato Then
		' get the parent (i.e. the <bb> tag)
		Set objParent = datenode.parentNode
		' remove it from the document
		xmldoc.documentElement.removeChild(objParent)
	end if
next
++++++++++++++++++++++++++

This will work because objParent is a pointer to a specific node on the
tree, and so the removeChild method will know which node to remove.

A neater way of doing it, since you are using the MSXML DOM, is to do this
(where trans_date is del_date converted to the correct format for comparing
with the xml):

+++++++++++++++++++++++++++++++++++++++++++
Set objNodeList = xmldom.documentElement.selectNodes("//bb[gen_date/text() =
'" & trans_date & "']")

For each objNode in objNodeList
	xmldoc.documentElement.removeChild(objNode)
Next

++++++++++++++++++++++++++++++++++++++++++

and then save it back to the file system.

Rgs,

Ben


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread