I want to export these xml tags from c#....

<Mujeeb>
    <ID>1</ID>
    <NAME>Table</NAME>
    <ORIGINAL_NAME>Table</ORIGINAL_NAME>
    <TYPE>Table</TYPE>
  <FORMAT>
    <ID>0</ID>
  </FORMAT>
</Mujeeb>

But the code i code output different result even after i created the Child and Parent table relationship.

<Mujeeb>
  <Mujeeb>
    <ID>0</ID>
    <NAME>Table</NAME>
    <ORIGINAL_NAME>Table</ORIGINAL_NAME>
    <TYPE>Table</TYPE>
  </Mujeeb>
  <FORMAT>
    <ID>0</ID>
  </FORMAT>
</Mujeeb>

Not sure why is this happening...
I wrote the following code...

-----------------------------------------------------------------

DataSet tempds = new DataSet("Mujeeb");
DataTable temptb;
DataColumn tempcl;
DataColumn temprecl;
DataRow tempdr;

temptb = new DataTable("Mujeeb");

temprecl = new DataColumn("ID", System.Type.GetType("System.Int32"));
temptb.Columns.Add(temprecl);
tempcl = new DataColumn("NAME", System.Type.GetType("System.String"));
temptb.Columns.Add(tempcl);
tempcl = new DataColumn("ORIGINAL_NAME", System.Type.GetType("System.String"));
temptb.Columns.Add(tempcl);
tempcl = new DataColumn("TYPE", System.Type.GetType("System.String"));
temptb.Columns.Add(tempcl);
                
tempdr = temptb.NewRow();
tempdr["ID"] = 0;
tempdr["Name"] = "Table";
tempdr["ORIGINAL_NAME"] = "Table";
tempdr["TYPE"] = "Table";
temptb.Rows.Add(tempdr);

tempds.Tables.Add(temptb);

temptb = new DataTable("FORMAT");
temprecl = new DataColumn("ID", System.Type.GetType("System.Int32"));
temptb.Columns.Add(temprecl);

tempdr = temptb.NewRow();
tempdr["GMARoot_ID"] = 0;
temptb.Rows.Add(tempdr);

tempds.Tables.Add(temptb);

tempds.Tables["Mujeeb"].ChildRelations.Add("Mujeeb_FORMAT", tempds.Tables["Mujeeb"].Columns["ID"], tempds.Tables["FORMAT"].Columns["ID"]);

-------------------------------------------------------------------


Can anyone please help me out in this...

Thx,
Mujeeb.

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

Why don't you write an XML serialization method yourself? The DataTable and DataSet xml serializations can add a lot of other stuff to the XML file.

You can also create your columns like this:

DataTable dtBeer = new DataTable();
        dtBeer.TableName = "Beer"; //Very important to set the table name when serializing datatables
        dtBeer.Columns.Add(new DataColumn("Brand", typeof(string)));
        dtBeer.Columns.Add(new DataColumn("SOH", typeof(int))); //"SOH" - Stock on hand
        dtBeer.Columns.Add(new DataColumn("OrderQty", typeof(int))); //amt to pick up next time you're at the store. This could make your list :)
        dtBeer.Columns["Brand"].Unique = true;

This way you're using a strong reference to the type instead of parsing a string.

You can serialize a List<T> for basic list serialization and use the XmlIgnore attributes to control what properties get serialized.

I want to output this xml tags

<Mujeeb>
<ID>1</ID>
<NAME>Table</NAME>
<ORIGINAL_NAME>Table</ORIGINAL_NAME>
<TYPE>Table</TYPE>
<FORMAT>
<ID>0</ID>
</FORMAT>
</Mujeeb>

My code that i wrote , first creates the tables and add it to Dataset, then i send that dataset to the xml class to save it in a file.

Help me to export the xml that i need..

thx,
Mujeeb.

Edited 6 Years Ago by peter_budo: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This article has been dead for over six months. Start a new discussion instead.