Click here to Skip to main content
11,717,509 members (77,486 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET XML
<make name="BMW">
    <model name="3 Series">
      <color name="Red" />
      <color name="Black" />
      <color name="Blue" />
    </model>
</make>

I want to insert record in this above format in xml file using c#;
can anyone suggest me some way through which i can create sub node or tree format data in xml.

Thanks in advance
Posted 11-Sep-12 2:01am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Refer this link
http://www.dotnetperls.com/xmlwriter
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/ee16f840-c983-40f0-a0b6-e664bf4b38fe

Try this code
using (XmlWriter writer = XmlWriter.Create(Server.MapPath("BMW.xml")))
            {
                string[] Color = new string[3] { "Red", "Black", "Blue" };
                writer.WriteStartDocument();
                writer.WriteStartElement("make");
                writer.WriteAttributeString("name", "BMW");               
                writer.WriteStartElement("model");
                writer.WriteAttributeString("name", "3 Series");                
 
                for (int i = 0; i < Color.Length; i++)
                {
                    writer.WriteStartElement("Color");
                    writer.WriteAttributeString("name", Color[i].ToString());                    
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
  Permalink  
v2
Comments
biswarup88 at 12-Sep-12 0:34am
   
Thanks pradiprenushe
biswarup88 at 12-Sep-12 0:48am
   
This above code works only once; if i run this code xml file is only overwritten with same data. what i have to do if i want to update the xml file so that records are generating continuously?
pradiprenushe at 12-Sep-12 1:10am
   
Go through this link
http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/e3f3c6b1-43ee-46d7-bc09-edb8dcedb8d1
biswarup88 at 12-Sep-12 1:16am
   
[:)]
Thanks a lot
pradiprenushe at 12-Sep-12 1:21am
   
Welcome
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 689
1 OriginalGriff 255
2 F-ES Sitecore 210
3 Jochen Arndt 120
4 Maciej Los 120
0 Sergey Alexandrovich Kryukov 1,144
1 Maciej Los 509
2 OriginalGriff 505
3 Richard MacCutchan 440
4 CHill60 415


Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 11 Sep 2012
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