Friday, 12 September 2014

MSXML Remove Node Not Behaving As Expected



I am trying to delete a node from the following XML - Data below is only representative of the acutal data:



<StaffMembers>
<Staff Name="Test1" Date="Date1"/>
<Staff Name="Test2" Date="Date2"/>
</StaffMembers>


My code is as follows:



Sub DeleteRecord(strName as string, strDate as string)

'Load Document

Set xList = xDoc.SelectNodes("//StaffMembers/")
for each xNode in xList
If xNode.Attributes.Length > 0 And xNode.Attributes.getNamedItem("Date").NodeValue = strDate Then
xnode.parentnode.removechild xnode
exit for
End if
next xNode

'Save Document

End Sub


The correct node is selected, but it is only partially deleted. If I open the resulting XML in Notepad, some of the text of the node remains. Can anyone explain this?


Thanks


No comments:

Post a Comment