Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fredrik Esseen 610 posts 906 karma points
    Dec 08, 2009 @ 16:29
    Fredrik Esseen
    0

    Fill Dataset from generated XML

    Hi!

    Im trying to generate an excel from generated xml but having trouble coding :)

    The reason Im doing this is that I have a custom table where one part is filled with xml excactly as Umbraco does storing XML. Now I want to build an xmlstructure from all these rows in the table and write it out as excel.

    The problem is that I dont now how to fill the dataset? normally I use ds.ReadXML("Filename") but now I dont have a file.

    string

     

    sqlstr = "SELECT XML FROM xxx WHERE xx = 'xx'";

     

    IRecordsReader reader = umbraco.BusinessLogic.Application.SqlHelper.ExecuteReader(sqlstr);

     

    XmlDocument doc = new XmlDocument();

     

    XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);

    doc.AppendChild(dec);

     

    XmlElement root = doc.CreateElement("Bookings");

    doc.AppendChild(root);

     

    while (reader.Read())

    {

     

    string strXML = reader.GetString("XML");

     

     

    XmlNode CurrentNode;

     

    XmlTextReader xmlReader = new XmlTextReader(new StringReader(strXML));

    CurrentNode = doc.ReadNode(xmlReader);

    root.AppendChild(CurrentNode);

    }

     

    Response.ContentType =

    "application/vnd.ms-excel";

    Response.Charset =

    "iso-8859-1";

    Response.ContentEncoding = System.Text.

    Encoding.GetEncoding("ISO-8859-1");

     

    Response.AddHeader(

    "Content-Disposition", "attachment;filename=" + "bookings" + ".xls");

     

    this.EnableViewState = false;

    System.IO.

    StringWriter tw = new System.IO.StringWriter();

    System.Web.UI.

    HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);

     

    DataGrid dgrid = new DataGrid();

     

    DataSet ds = new DataSet();

     

    // Here is the problem:

    ds.readXML()???

     

    //What syntax should I use?

     

    dgrid.DataSource = ds;

    dgrid.DataBind();

     

    dgrid.RenderControl(hw);

    Response.Write(tw.ToString());

    Response.Flush();

    Response.End();

Please Sign in or register to post replies

Write your reply to:

Draft