I have some code that allows users to download an xml file to their PCs. I am storing the xml in an XmlDocument and saving that via the Response.Output. Saving the xml in this way seems to be adding on an xml declaration because the xml I am loading doesn't
include one.
Does anyone know how to get rid of the declaraction that is getting added?
aoloki
0 Points
3 Posts
Removing XML Declaration From Download
Jan 04, 2013 07:25 PM|LINK
I have some code that allows users to download an xml file to their PCs. I am storing the xml in an XmlDocument and saving that via the Response.Output. Saving the xml in this way seems to be adding on an xml declaration because the xml I am loading doesn't include one.
Does anyone know how to get rid of the declaraction that is getting added?
Response.Clear(); Response.ClearHeaders(); Response.AddHeader("Content-disposition", "attachment; filename=pol" + tblPols.Rows[Convert.ToInt16(storeRowID.Value)].Cells[1].Text + ".xml"); Response.ContentType = "text/xml"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.Cache.SetAllowResponseInBrowserHistory(true); doc.Save(Response.Output); Response.Flush(); Response.End();Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing XML Declaration From Download
Jan 06, 2013 02:35 AM|LINK
Hi,
What result do you fetch after using the codes above?
aoloki
0 Points
3 Posts
Re: Removing XML Declaration From Download
Jan 07, 2013 01:20 PM|LINK
I get the XML that I want tagged with the following header.
<?xml version="1.0" encoding="utf-8" ?>
I do not want this header.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing XML Declaration From Download
Jan 08, 2013 12:07 AM|LINK
Hello,
1) Please use XDocument.Load to load the xml file or string (to load string, please use Parse).
2) Then re-write to another file with XDocunent's Root property.
aoloki
0 Points
3 Posts
Re: Removing XML Declaration From Download
Jan 08, 2013 08:11 PM|LINK
Still not working.
It seems to be something to do with this line
Response.AddHeader("Content-disposition", "attachment; filename=pol" + tblPols.Rows[Convert.ToInt16(storeRowID.Value)].Cells[1].Text + ".xml");If I make it a ".txt" file instead it will not include the header. Is there a way to default a filename without using that?
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Removing XML Declaration From Download
Jan 10, 2013 12:24 AM|LINK
Hi,
No.
I mean that you can just output your xml in the formation of string, and then do saving. Because if in "string" mode, you can remove that headerline.