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. C#
  4. Create XML file with C#

Create XML file with C#

Scheduled Pinned Locked Moved C#
csharpxmlhelpquestion
3 Posts 3 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.
  • R Offline
    R Offline
    RivasBoy
    wrote on last edited by
    #1

    I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.

    The button should generate an xml file.

    I can create the xml file and write the data from text boxes, but not the DataGrid.

    Anyone can help me?

    At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:

    <Tabela>
    <Tabela-Linha numero="1">
    <Id>01</id>
    <Nome>Teste1</Nome>
    <Cargo>xxx</Cargo>
    <Extensao>500</Extensao>
    </Tabela-Linha>
    <Tabela-Linha numero="2">
    <Id>02</id>
    <Nome>teste2</Nome>
    <Cargo>xxxx</Cargo>
    <Extensao>501</Extensao>
    </Tabela-Linha>
    </Tabela>

    Can anyone help me?

    L N 2 Replies Last reply
    0
    • R RivasBoy

      I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.

      The button should generate an xml file.

      I can create the xml file and write the data from text boxes, but not the DataGrid.

      Anyone can help me?

      At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:

      <Tabela>
      <Tabela-Linha numero="1">
      <Id>01</id>
      <Nome>Teste1</Nome>
      <Cargo>xxx</Cargo>
      <Extensao>500</Extensao>
      </Tabela-Linha>
      <Tabela-Linha numero="2">
      <Id>02</id>
      <Nome>teste2</Nome>
      <Cargo>xxxx</Cargo>
      <Extensao>501</Extensao>
      </Tabela-Linha>
      </Tabela>

      Can anyone help me?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      How about foreaching the [Rows](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx)[[^](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rows.aspx "New Window")] collection of the grid, writing the contents of all the [Columns](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns.aspx)[[^](http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.columns.aspx "New Window")] using the method you already used?

      object value = dataGridView1.Rows[RowIndex].Cells[ColumnIndex].Value;

      Bastard Programmer from Hell :suss:

      1 Reply Last reply
      0
      • R RivasBoy

        I developed an application in C # where I have 4 text boxes and a datagrid with 4 columns and multiple rows and a button.

        The button should generate an xml file.

        I can create the xml file and write the data from text boxes, but not the DataGrid.

        Anyone can help me?

        At this moment i have this code: In the button action XmlTextWriter writer = new XmlTextWriter("teste.xml", Encoding.GetEncoding("ISO-8859-1")); Writer.Formatting = Formatting.Indented; // for the textboxes: WriteStartElement("textbox1"); WriteElementString(textbox1.text); WriteEndElement(); WriteStartElement("textbox2"); WriteElementString(textbox2.text); WriteEndElement(); WriteStartElement("textbox3"); WriteElementString(textbox3.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); WriteStartElement("textbox4"); WriteElementString(textbox4.text); WriteEndElement(); For the datadridview xml output strutured shoud be like this:

        <Tabela>
        <Tabela-Linha numero="1">
        <Id>01</id>
        <Nome>Teste1</Nome>
        <Cargo>xxx</Cargo>
        <Extensao>500</Extensao>
        </Tabela-Linha>
        <Tabela-Linha numero="2">
        <Id>02</id>
        <Nome>teste2</Nome>
        <Cargo>xxxx</Cargo>
        <Extensao>501</Extensao>
        </Tabela-Linha>
        </Tabela>

        Can anyone help me?

        N Offline
        N Offline
        Nathan Stiles
        wrote on last edited by
        #3

        How about using a serializable object as the datasource for the grid then serialize the object?

        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