Home > ASP.NET > Rename xml tag name in C#

Rename xml tag name in C#

XmlTextReader reader = new XmlTextReader(“Report.xml”);
XmlTextWriter tw = new XmlTextWriter(“NewReport.xml”, null);//null represents encoding
tw.Formatting = Formatting.Indented;  //for xml tags to be indented//
tw.WriteStartDocument();

while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.Element: // The node is an element.
if (reader.Name == “NewDataSet”)
{
tw.WriteStartElement(“root”);
}
else if (reader.Name == “Table”)
{
tw.WriteStartElement(“user”);
}

else

{

tw.WriteStartElement(reader.Name);

}

break;;
case XmlNodeType.Text: //Display the text in each element.
tw.WriteValue(reader.Value);
break;
case XmlNodeType.EndElement: //Display the end of the element.
tw.WriteEndElement();
break;
}
}

tw.Flush();
tw.Close();

Advertisements
Categories: ASP.NET
  1. sreeraj
    June 4, 2012 at 10:59 am

    second line i am getting error

    • June 7, 2012 at 6:31 am

      What error, can you post it here

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: