Groups | Blog | Home
all groups > c# > february 2008 >

c# : how to remove closing tag of a node of xml file in asp.net and c#



tosudesh2005@gmail.com
2/29/2008 9:01:44 PM
hi all

I write code like this to remove perticular node. but it left closing
tag in xml file. but i want remove this closing tag also.
------------------------------------------------------------
string filename = Server.MapPath("DutyStatus.xml").ToString();
XmlNodeList objnodelst;
XmlDocument doc = new XmlDocument();
doc.Load(filename);
objnodelst = doc.SelectNodes("/DutyStatus/
DSNO[@ID='30006006200']");
foreach (XmlNode objnode in objnodelst)
{
objnode.RemoveAll();
doc.Save(Server.MapPath("DutyStatus.xml"));
}



my xml file look like this
-------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
- <DutyStatus>
- <DSNO ID="30006006200">
<UserID>AMIT KUMAR - 17</UserID>
<Status>frmDutyStart</Status>
</DSNO>
</DutyStatus

after deleting this node my file look like this
------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
- <DutyStatus>
<DSNO />
</DutyStatus

i want remove <DSNO/> tag also

from
Arne_Vajhøj
3/1/2008 12:25:25 AM
[quoted text, click to view]

You are only removing content below objnode.

You need to remove objnode from its parent.

tosudesh2005@gmail.com
3/1/2008 4:00:45 AM
[quoted text, click to view]

thanks dear,
AddThis Social Bookmark Button