malashukla 0 Light Poster

hi i m trying a code to execute in order to generate a xml file at runtime.
it execute well. but the xml file gives a error as

The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

Only one top level element is allowed in an XML document. Error processing resource 'file:///D:/HelloJhasi/glance/jhansigal...

my code is

public bool createxml()
    {
        DataSet ds = new DataSet();
        clsRegister obj = new clsRegister();
        int i = 0;
        string strpath = string.Empty;
        XmlTextWriter objwriter = new XmlTextWriter(Console.Out);
        ds = obj.searchgallery(4);
        try
        {
            strpath = "d:\\hellojhasi\\glance\\jhansigallery\\gallery.xml";
            objwriter = new XmlTextWriter(strpath, System.Text.Encoding.Default);
            if (ds.Tables[0].Rows.Count > 0)
            {

                for (i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                   objwriter.WriteStartElement("picturegallery");
                    objwriter.WriteElementString("fullimage", ds.Tables[0].Rows[i]["fullimage"].ToString());
                    objwriter.WriteElementString("thumbnail", ds.Tables[0].Rows[i]["thumbnail"].ToString());
                    objwriter.WriteElementString("title", ds.Tables[0].Rows[i]["title"].ToString());
                    objwriter.WriteElementString("description", ds.Tables[0].Rows[i]["description"].ToString());
                    objwriter.WriteElementString("height", ds.Tables[0].Rows[i]["height"].ToString());
                    objwriter.WriteElementString("width", ds.Tables[0].Rows[i]["width"].ToString());
                    objwriter.WriteEndElement();
                }
            }
            else
            {

                objwriter.WriteEndElement();
            }
            objwriter.Flush();

        }

could anyone help plz

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.