How to delete tags froman XML file

jsn1

Member
Joined
Jul 14, 2006
Messages
12
Programming Experience
10+
Hi all.

I would like to delete some tags from an XML file, to create a dataset and bound it to a datagrid.


I have this XML file as an entry:
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML>
<RESPONSE>
<family>
<name gender="Male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
</name>
<name gender="Female">
<firstname>Dale</firstname>
<lastname>Smith</lastname>
</name>
</family>
</RESPONSE>
</ARCXML>

I would like to delete the tags <ARCXML> and <RESPONSE> to get this file:
HTML:
<?xml version="1.0" encoding="UTF-8"?>
<family>
<name gender="Male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
</name>
<name gender="Female">
<firstname>Dale</firstname>
<lastname>Smith</lastname>
</name>
</family>
and process this new file.

How can I do it?
thanks
jsn
 
Last edited by a moderator:
Get the 'family' node, remove the 'ARCXML' node, append the 'family' node again. Example (xdoc is XmlDocument):
VB.NET:
Dim xe As Xml.XmlElement = xdoc.SelectSingleNode("ARCXML/RESPONSE/family")
xdoc.RemoveChild(xdoc.DocumentElement)
xdoc.AppendChild(xe)
 
Back
Top