Changing XML Node name using C#

HI ;
I have the following XML
 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<ActualKPIAxisMinuteImport>
  <ActualKPIAxisMinute>
     <XrefCode>00218</XrefCode>
     <DayId>2011-04-04</DayId>
     <MinuteId>2011-04-04T10:00:00</MinuteId>
     <AxisId>8</AxisId>
     <TicXrefCode>Sales</TicXrefCode>
     <KpiId>29</KpiId>
     <Value>4</Value>
     </ActualKPIAxisMinute>
  <ActualKPIAxisMinuteImport>
<ActualKPIAxisMinuteImport>


And I Want to change The first Node <ActualKPIAxisMinuteImport> to <ActualKPIAxisMinuteImport AggregateToDay="true"> to get the following result

 <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

<ActualKPIAxisMinuteImport AggregateToDay="true">
  <ActualKPIAxisMinute>
     <XrefCode>00218</XrefCode>
     <DayId>2011-04-04</DayId>
     <MinuteId>2011-04-04T10:00:00</MinuteId>
     <AxisId>8</AxisId>
     <TicXrefCode>Sales</TicXrefCode>
     <KpiId>29</KpiId>
     <Value>4</Value>
     </ActualKPIAxisMinute>
  <ActualKPIAxisMinuteImport>
<ActualKPIAxisMinuteImport>

How to do that with C# ?
FatehbourghoudAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Carl TawnSystems and Integration DeveloperCommented:
What you are actually wanting to do is to append an attribute to the documents root node. You can do this with something like:
            string filename = "C:\\test.xml";

            XmlDocument doc = new XmlDocument();
            doc.Load(filename);

            XmlAttribute attr = doc.CreateAttribute("AggregateToDay");
            attr.Value = "true";

            doc.DocumentElement.Attributes.SetNamedItem(attr);
            doc.Save(filename);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FatehbourghoudAuthor Commented:
Thanks Carl ;

I really appriciate your help
0
FatehbourghoudAuthor Commented:
Very helpfull and excelent solution

Thanks Carl
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.