Sign in to follow this  
Pallav

HOW TO GENERATE A XML FROM DATASET

Recommended Posts

hi i am facing a problem..

 

the thing is that i have to populate the xml form datset based on the dataset values.How to add the root element and child elmets according to tht

 

 

 

here is my code.. pls help me out

 

 

 

 

 

protected void Button1_Click(object sender, EventArgs e)

 

{

 

 

 

 

 

 

 

strXML =;

 

strXML+= "";

 

 

 

strXML += "";

 

 

 

strXML += "";

 

 

 

strXML += "";

 

 

 

strXML += "";

 

 

 

strXML += "";

 

 

 

strXML += "";

 

 

 

SqlDataAdapter da = new SqlDataAdapter("select * from Test_Gantt", con);

 

 

 

DataSet ds = new DataSet();

 

da.Fill(ds, "ds");

 

 

 

//Iterate through each Record

 

 

 

foreach (DataRow dr in ds.Tables[0].Rows)

 

{

 

 

 

strXML += "";

 

 

 

}

 

 

 

con.Close();

 

 

 

strXML += "";

 

 

 

 

 

strXML += "";

 

 

 

 

 

 

 

FileStream fs = new FileStream(Server.MapPath("My_ Xml_ Files/emp6.xml"), FileMode.Create);

 

fs.Write(strXML);

 

 

 

 

 

}

code.txt

Edited by Guest

Share this post


Link to post
Share on other sites

You can iterate through the dataset and then use string concatenation to build XML. Please see www.fusioncharts.com/docs > Guide for web developers.

Share this post


Link to post
Share on other sites

Basically its:

 

 

 

For (int i = 0; i < ds.Tables[0].rows.count; i++)

 

{

 

strxml+= < set name= ds.Tables[0].rows[column number of name].toString(), value= ds.Tables[0].rows[column number of value].toString() / >

 

}

Edited by Guest

Share this post


Link to post
Share on other sites

strXML +=

"<categories>";

while (oRs.ReadData.Read())

{

strXML +=

"<category name='" + oRs.ReadData["Day Name"].ToString() + "' />";

}

strXML +=

"</categories>";

 

Use the  XML tag which you want instead of categories.

Share this post


Link to post
Share on other sites

strXML +=

"<categories>";

while (oRs.ReadData.Read())

{

strXML +=

"<category name='" + oRs.ReadData["Day Name"].ToString() + "' />";

}

strXML +=

"</categories>";

 

use the Required XML tag instead of categories

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this