Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. how to write xml in C#.net

how to write xml in C#.net

Scheduled Pinned Locked Moved XML / XSL
csharpxmlhelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anumadhu
    wrote on last edited by
    #1

    Hello can anyone help me in getting the xml file's root node in the following format. Here Schedule is root node. I am using the XmlTextWriter class. - Can anyone help me in this regards... Thanks Anee Anee

    S 1 Reply Last reply
    0
    • A anumadhu

      Hello can anyone help me in getting the xml file's root node in the following format. Here Schedule is root node. I am using the XmlTextWriter class. - Can anyone help me in this regards... Thanks Anee Anee

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Show us the code that you got so far and we'll tell you what has to be changed. Don't expect someone to write the whole code for you.


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      A 1 Reply Last reply
      0
      • S Stefan Troschuetz

        Show us the code that you got so far and we'll tell you what has to be changed. Don't expect someone to write the whole code for you.


        "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

        www.troschuetz.de

        A Offline
        A Offline
        anumadhu
        wrote on last edited by
        #3

        Hello, I did, like this.. and got the root element, in the way.. which my sample xml document contains. But i am not much sure, that whether the method that i followed is correct or not. please help me out in fixing whether this is right or not. This the piece of code, which i wrote to write the root node .. according to my requirement.. //writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule"); writer.WriteStartElement("tns:schedule"); writer.WriteAttributeString("xmlns:tns", "", "http://www.MyCompany.com/Schedule"); writer.WriteAttributeString("xmlns:dt", "","http://www.MyCompany.com/DataTypes"); writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi:schemaLocation", "http://www.MyCompany.com/Schedule Schedule.xsd"); writer.WriteAttributeString("scheduleType", "Playback"); writer.WriteAttributeString("version", "1.0"); writer.WriteAttributeString("creationTime", "2006-01-29T00:00:00"); writer.WriteAttributeString("originator", "MyCompany"); writer.WriteStartElement("scope"); writer.WriteAttributeString("startTime", "2006-01-29T04:00:00".ToString()); writer.WriteAttributeString("stopTime", "2006-01-29T06:00:00".ToString()); writer.WriteEndElement(); //use the record structure int i = 0, count; count = xmlSlotNodes.Count; // sort the slots according to there callSign xmlSlotNodes.Sort(0,count,new Sorting ()); string[] prgmTime = new string[2]; ---- ---- Thank you Anee

        S 1 Reply Last reply
        0
        • A anumadhu

          Hello, I did, like this.. and got the root element, in the way.. which my sample xml document contains. But i am not much sure, that whether the method that i followed is correct or not. please help me out in fixing whether this is right or not. This the piece of code, which i wrote to write the root node .. according to my requirement.. //writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule"); writer.WriteStartElement("tns:schedule"); writer.WriteAttributeString("xmlns:tns", "", "http://www.MyCompany.com/Schedule"); writer.WriteAttributeString("xmlns:dt", "","http://www.MyCompany.com/DataTypes"); writer.WriteAttributeString("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi:schemaLocation", "http://www.MyCompany.com/Schedule Schedule.xsd"); writer.WriteAttributeString("scheduleType", "Playback"); writer.WriteAttributeString("version", "1.0"); writer.WriteAttributeString("creationTime", "2006-01-29T00:00:00"); writer.WriteAttributeString("originator", "MyCompany"); writer.WriteStartElement("scope"); writer.WriteAttributeString("startTime", "2006-01-29T04:00:00".ToString()); writer.WriteAttributeString("stopTime", "2006-01-29T06:00:00".ToString()); writer.WriteEndElement(); //use the record structure int i = 0, count; count = xmlSlotNodes.Count; // sort the slots according to there callSign xmlSlotNodes.Sort(0,count,new Sorting ()); string[] prgmTime = new string[2]; ---- ---- Thank you Anee

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          Looks quite ok, but - For starting the root element you should use the following overload of the WriteStartElement method, cause the one that is currently used expects a local name and not a qualified name:

          writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule");

          - For writing the namespace declarations you should use the following overload, cause the one that is currently used also expects a local name and not a qualified name:

          writer.WriteAttributeString("xmlns", "tns", null, "http://www.MyCompany.com/Schedule");
          writer.WriteAttributeString("xmlns", "dt", null,"http://www.MyCompany.com/DataTypes");
          writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
          writer.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.MyCompany.com/Schedule Schedule.xsd");


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          A 1 Reply Last reply
          0
          • S Stefan Troschuetz

            Looks quite ok, but - For starting the root element you should use the following overload of the WriteStartElement method, cause the one that is currently used expects a local name and not a qualified name:

            writer.WriteStartElement("tns", "schedule", "http://www.MyCopmpany.com/Schedule");

            - For writing the namespace declarations you should use the following overload, cause the one that is currently used also expects a local name and not a qualified name:

            writer.WriteAttributeString("xmlns", "tns", null, "http://www.MyCompany.com/Schedule");
            writer.WriteAttributeString("xmlns", "dt", null,"http://www.MyCompany.com/DataTypes");
            writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
            writer.WriteAttributeString("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "http://www.MyCompany.com/Schedule Schedule.xsd");


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

            A Offline
            A Offline
            anumadhu
            wrote on last edited by
            #5

            Hello Stefan!! Great thanks... Its works fine. Thank you Anee Anee

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups