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 also remove <DSNO/> tag also

from
sudesh
 
C

Chris Dunaway

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 also remove <DSNO/> tag also

from
sudesh

This group is for VB.Net related questions. Please ask your question
in a C# group.

Chris
 
J

Just_a_fan

Here's some code I wrote to break down XML myself. No, it is not the
W3C standard but it does ignore errors as per the standard. The routine
knocks off the start and end tags and returns what is in between them.
This seems to be what you want. It handles start tags like <start> and
<start a=3>.

First, sample calls:

sTempUnit = ExtractXML("weather", sMystring) ' Narrow to the
"weather" group
sTempUnit = ExtractXML("head", sTempUnit) ' Get down to the
headings group
sTempUnit = ExtractXML("ut", sTempUnit) ' Get unit for
temperature (only item in ut)
sTemp = ExtractXML("weather", sMystring) ' Narrow to the
"weather" group
sTemp = ExtractXML("cc", sTemp) ' Narrow to "cc" within
"weather"
sUpdtTime = ExtractXML("lsup", sTemp) ' Get last update time
lFindTime = InStr(sUpdtTime, " ")
sUpdtTime = Mid(sUpdtTime, lFindTime)
sUpdtTime = Strings.Left(sUpdtTime, Len(sUpdtTime) - 4)
-------------------------------------------------------------------------
Function ExtractXML(ByVal sTag As String, ByVal sInput As String) As
String

'This was written to embody the XML philosophy. If there is
anything wrong, don't complain, just go away quietly!

Dim MyPos1 As Integer, MyPos2 As Integer
Dim sUInput As String, sUTag As String

If Strings.Len(sInput) = 0 Then
ExtractXML = ""
Exit Function
End If

sUInput = UCase(sInput)
sUTag = UCase(sTag)

MyPos1 = InStr(1, sUInput, "<" & sUTag & ">")
If MyPos1 = 0 Then
MyPos1 = InStr(1, sUInput, "<" & sUTag & " ")
If MyPos1 = 0 Then
ExtractXML = ""
Exit Function
End If
End If

MyPos1 = InStr(MyPos1, sUInput, ">")
If MyPos1 = 0 Then
ExtractXML = ""
Exit Function
End If

MyPos2 = InStr(MyPos1, sUInput, "</" & sUTag, MyPos1)
If MyPos2 = 0 Then
ExtractXML = ""
Exit Function
End If

ExtractXML = Strings.Trim(Mid(sInput, MyPos1 + 1, MyPos2 - MyPos1 -
1))

End Function

-----------------------------------------------------------
Mike



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 also remove <DSNO/> tag also

from
sudesh
 

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