Click here to Skip to main content
11,930,788 members (57,726 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
I have xml file like this

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
        <Name>Mp3 Player</Name>
            <FiveToNine>Old Kannada</FiveToNine>
            <NineToLeven>New Kannada</NineToLeven>
            <LevenToThirteen>New Hindi</LevenToThirteen>
            <ThirteenToFourteen>Old Hindi</ThirteenToFourteen>
            <ForteenToFifteen>Old English</ForteenToFifteen>
            <FifteenToSeventeen>New English</FifteenToSeventeen>
            <SeventeenToEighteen>Old Malayalam</SeventeenToEighteen>
            <EighteenToTwenty>New Malayalam</EighteenToTwenty>
            <TwentyToTwentytwo>Old Tamil</TwentyToTwentytwo>
            <TwentytwoToTwentyfour>New Tamil</TwentytwoToTwentyfour>

Now I want to add a new node list inside node, and I want to update the value of one node inside node.

Can any one help me please?

Thanks in @dv@nce....:P
Posted 5-Jul-13 3:16am
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Plain and simple... to change i.e.
var doc = XDocument.Load([FILENAME]);
doc.Root["Body"]["Monday"]["FiveToNine"] = "What ever";
to add
var myNewElement = new XElement("NodeName", "NodeValue");
and save it afterwards...

Maybe you want to take a look at these pages[^]

Sorry, mixed up XmlDocument and XDocument....

static void Main(string[] args) 
    var doc = new XmlDocument();
    //To change
    doc["MediaPlayer"]["Body"]["Name"].InnerText = "Something else";
    //To add
    var newNode = doc.CreateElement("Wednesday");
Aboobakkar Siddeq D.U 6-Jul-13 1:58am
I'm not able use doc.Root["Body"]["Monday"]["FiveToNine"] = "Something"; System is throwing error like "Cannot apply indexing with [] to an expression of type 'System.Xml.Linq.XElement'",
What is the solution for that?
s_mon 6-Jul-13 2:14am
Changed the solution... got a little bit mixed up... jst fiddle a little bit around to get a grip on the context.
Aboobakkar Siddeq D.U 6-Jul-13 2:24am
Now how can I remove that error?
s_mon 6-Jul-13 2:54am
Just use the code with the XmlDocument...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.151126.1 | Last Updated 6 Jul 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100