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. Web Development
  3. ASP.NET
  4. convert database to xml file (but i want column as attribute) [modified]

convert database to xml file (but i want column as attribute) [modified]

Scheduled Pinned Locked Moved ASP.NET
databasedesignsysadminsecurityxml
4 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.
  • P Offline
    P Offline
    Punit Belani
    wrote on last edited by
    #1

    hi.. i already convert database table to xml but it create new element for each column but i want each column as attribute.. code i have is as below: public partial class Default2 : System.Web.UI.Page {       protected void Page_Load(object sender, EventArgs e)       {             DataSet ds = GetDataSet();             myXMLControl.DocumentContent = ds.GetXml();                   }       public DataSet GetDataSet()       {             DataSet result = new DataSet();             string connString                   = "server=192.0.0.1;user id=test;password=123;persist security info=True;database=MLM1";             using (MySqlConnection myConnection = new MySqlConnection(connString))             {                   string query                         = "Select userid,code,parent_id from _relation";                   MySqlCommand myCommand = new MySqlCommand(query, myConnection);                   MySqlDataAdapter myAdapter = new MySqlDataAdapter();                   myCommand.CommandType = CommandType.Text;                   myAdapter.SelectCommand = myCommand;                   myAdapter.Fill(result);                   myAdapter.Dispose();             }             result.DataSetName = "root";             result.Tables[0].TableName = "Node";             DataRelation relation = new DataRelation("ParentChild",//tab.Columns.Add("userid"),tab.Columns.Add("parent_id"),true);

    N 1 Reply Last reply
    0
    • P Punit Belani

      hi.. i already convert database table to xml but it create new element for each column but i want each column as attribute.. code i have is as below: public partial class Default2 : System.Web.UI.Page {       protected void Page_Load(object sender, EventArgs e)       {             DataSet ds = GetDataSet();             myXMLControl.DocumentContent = ds.GetXml();                   }       public DataSet GetDataSet()       {             DataSet result = new DataSet();             string connString                   = "server=192.0.0.1;user id=test;password=123;persist security info=True;database=MLM1";             using (MySqlConnection myConnection = new MySqlConnection(connString))             {                   string query                         = "Select userid,code,parent_id from _relation";                   MySqlCommand myCommand = new MySqlCommand(query, myConnection);                   MySqlDataAdapter myAdapter = new MySqlDataAdapter();                   myCommand.CommandType = CommandType.Text;                   myAdapter.SelectCommand = myCommand;                   myAdapter.Fill(result);                   myAdapter.Dispose();             }             result.DataSetName = "root";             result.Tables[0].TableName = "Node";             DataRelation relation = new DataRelation("ParentChild",//tab.Columns.Add("userid"),tab.Columns.Add("parent_id"),true);

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      DataSet provides limited options to extend the XML writing behavior. To create a custom XML format like you mentioned, you may need to create your own serializable type and add proper attributes to it. You can use XmlSerializer[^] to serialize this into a stream or file.

      Navaneeth How to use google | Ask smart questions

      P 1 Reply Last reply
      0
      • N N a v a n e e t h

        DataSet provides limited options to extend the XML writing behavior. To create a custom XML format like you mentioned, you may need to create your own serializable type and add proper attributes to it. You can use XmlSerializer[^] to serialize this into a stream or file.

        Navaneeth How to use google | Ask smart questions

        P Offline
        P Offline
        Punit Belani
        wrote on last edited by
        #3

        i tried that but i hav no gud idea for serializable.. can you post code snippet for that?? thanks..

        N 1 Reply Last reply
        0
        • P Punit Belani

          i tried that but i hav no gud idea for serializable.. can you post code snippet for that?? thanks..

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          punit_belani wrote:

          i hav no gud idea for serializable

          What is wrong in checking MSDN documentation? :doh: Any way here is a sample,

          using System.Xml;
          using System.Xml.Serialization;
          using System.IO;

          [Serializable]
          public class Person
          {
          [XmlAttribute("Name")]
          public string Name { get; set; }

          \[XmlElement\]
          public int Age { get; set; }
          

          }

          Person person = new Person()
          {
          Name = "Chuck norris",
          Age = 40
          };

          using (FileStream fs = new FileStream("person.xml", FileMode.Create, FileAccess.Write))
          {
          XmlSerializer serializer = new XmlSerializer(typeof(Person));
          serializer.Serialize(fs, person);
          }

          The attributes on each property tells the XmlSerializer object about the way it should produce output XML. :)

          Navaneeth How to use google | Ask smart questions

          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