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

T

tosudesh2005

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
sudesh
 
A

Arne Vajhøj

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

You are only removing content below objnode.

You need to remove objnode from its parent.

Arne
 
T

tosudesh2005

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

You are only removing content below objnode.

You need to remove objnode from its parent.

Arne- Hide quoted text -

- Show quoted text -

thanks dear,
i got solution of my problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top