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. formatting XML problem

formatting XML problem

Scheduled Pinned Locked Moved C#
questiondatabasexmlhelp
2 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.
  • J Offline
    J Offline
    JockerSoft
    wrote on last edited by
    #1

    DataSet datas = new DataSet("DataSetName"); DataTable dataTable = new DataTable("myNewTableName"); DataRow dataRow = dataTable.NewRow(); dataTable.Rows.Add(dataRow); for(int i = 0; i<5; i++) { DataColumn dataColumn = new DataColumn();; dataColumn.ColumnName = "myColumnName"+i.ToString(); dataTable.Columns.Add(dataColumn); dataRow["myColumnName"+i.ToString()]="myItem"+i.ToString(); } dataTable.AcceptChanges(); datas.Tables.Add(dataTable); dataGrid1.DataSource=dataTable; datas.WriteXml("TestXml.xml"); This code generate the following xml file: -------------- myItem0 myItem1 myItem2 myItem3 myItem4 -------------- I need the same data to be formatted in this way: -------------- -------------- how can I do this? thanks _____________ http://members.xoom.virgilio.it/yuppygames/english/index.htm

    H 1 Reply Last reply
    0
    • J JockerSoft

      DataSet datas = new DataSet("DataSetName"); DataTable dataTable = new DataTable("myNewTableName"); DataRow dataRow = dataTable.NewRow(); dataTable.Rows.Add(dataRow); for(int i = 0; i<5; i++) { DataColumn dataColumn = new DataColumn();; dataColumn.ColumnName = "myColumnName"+i.ToString(); dataTable.Columns.Add(dataColumn); dataRow["myColumnName"+i.ToString()]="myItem"+i.ToString(); } dataTable.AcceptChanges(); datas.Tables.Add(dataTable); dataGrid1.DataSource=dataTable; datas.WriteXml("TestXml.xml"); This code generate the following xml file: -------------- myItem0 myItem1 myItem2 myItem3 myItem4 -------------- I need the same data to be formatted in this way: -------------- -------------- how can I do this? thanks _____________ http://members.xoom.virgilio.it/yuppygames/english/index.htm

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Don't use a DataSet. It outputs XML in specific ways - namely as elements. Instead, see the classes in the System.Xml namespace. You could enumerate the tables and columns in your DataSet (or use an XmlDataDocument) and then write them out to a file using an XmlTextWriter, which allows you to write attributes, elements, comments, and even processing instructions however you want. Lots of samples are included in the class documentation for the System.Xml namespace. One other option is to save this to a file or a MemoryStream and then load it into an XmlDocument or some other class. You could then use a XslTransform to transform the elements into attributes.

      Microsoft MVP, Visual C# My Articles

      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