This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Remove node in xml file from Visual Basic?


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@list.15seconds.com) 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]