471,594 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,594 software developers and data experts.

Problem with XML file?

I'm using the following code to create an Xml document to be saved by the
browser (IE):

MemoryStream stream = new MemoryStream();
OrderManager.ExportToXml(stream); // Creates Xml
by using XmlTextWriter to the stream

Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;
filename=BaldrianOrdersMamut.xml");
Response.BinaryWrite(stream.GetBuffer());
Response.End();

This is a sample of the saved Xml file:

<?xml version="1.0" encoding="utf-8"?>
<GBAOX10>
<ORDERLIST />
</GBAOX10>

The problem is that the resulting file that is saved doesn't seem 100%
right. When you read the content in Notepad it looks OK, but IE have a
problem displaying and show an error like this:

"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.

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

Invalid at the top level of the document. Error processing resource
'file:///C:/Documents and Settings/olavt.SAFARI/My Docu...

</GBAOX10>"

If I just do a File->Save in Notepad overwriting the original file, the
problem disappears.

How can I get the file to save correctly in the first place?

Olav


Nov 12 '05 #1
3 3264
Try inserting:
stream.Seek(0, SeekOrigin.Begin);
"Olav Tollefsen" <x@y.com> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
I'm using the following code to create an Xml document to be saved by the
browser (IE):

MemoryStream stream = new MemoryStream();
OrderManager.ExportToXml(stream); // Creates Xml
by using XmlTextWriter to the stream

Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;
filename=BaldrianOrdersMamut.xml");
Response.BinaryWrite(stream.GetBuffer());
Response.End();

This is a sample of the saved Xml file:

<?xml version="1.0" encoding="utf-8"?>
<GBAOX10>
<ORDERLIST />
</GBAOX10>

The problem is that the resulting file that is saved doesn't seem 100%
right. When you read the content in Notepad it looks OK, but IE have a
problem displaying and show an error like this:

"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.

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

Invalid at the top level of the document. Error processing resource
'file:///C:/Documents and Settings/olavt.SAFARI/My Docu...

</GBAOX10>"

If I just do a File->Save in Notepad overwriting the original file, the
problem disappears.

How can I get the file to save correctly in the first place?

Olav

Nov 12 '05 #2
That didn't help and caused invalid Xml to be generated.

Olav

"Chris Lovett" <so*****@nospam.please> wrote in message
news:PM********************@comcast.com...
Try inserting:
stream.Seek(0, SeekOrigin.Begin);
"Olav Tollefsen" <x@y.com> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
I'm using the following code to create an Xml document to be saved by the
browser (IE):

MemoryStream stream = new MemoryStream();
OrderManager.ExportToXml(stream); // Creates
Xml by using XmlTextWriter to the stream

Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;
filename=BaldrianOrdersMamut.xml");
Response.BinaryWrite(stream.GetBuffer());
Response.End();

This is a sample of the saved Xml file:

<?xml version="1.0" encoding="utf-8"?>
<GBAOX10>
<ORDERLIST />
</GBAOX10>

The problem is that the resulting file that is saved doesn't seem 100%
right. When you read the content in Notepad it looks OK, but IE have a
problem displaying and show an error like this:

"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.

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

Invalid at the top level of the document. Error processing resource
'file:///C:/Documents and Settings/olavt.SAFARI/My Docu...

</GBAOX10>"

If I just do a File->Save in Notepad overwriting the original file, the
problem disappears.

How can I get the file to save correctly in the first place?

Olav


Nov 12 '05 #3
The following aspx page:

<%@LANGUAGE=C#%>
<%@Import Namespace="System.Xml"%>
<%@Import Namespace="System.IO"%>
<%
MemoryStream stream = new MemoryStream();
XmlTextWriter writer = new XmlTextWriter(stream,
System.Text.Encoding.UTF8);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();
writer.WriteStartElement("GBAOX10");
writer.WriteStartElement("ORDERLIST");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Close();

Response.Clear();
Response.ContentType = "text/xml";
Response.AppendHeader("Content-Disposition", "attachment;
filename=BaldrianOrdersMamut.xml");
Response.BinaryWrite(stream.GetBuffer());
Response.End();
%>

Produces the following output:

<?xml version="1.0" encoding="utf-8"?>
<GBAOX10>
<ORDERLIST />
</GBAOX10>

"Olav Tollefsen" <x@y.com> wrote in message
news:uL**************@TK2MSFTNGP14.phx.gbl...
That didn't help and caused invalid Xml to be generated.

Olav

"Chris Lovett" <so*****@nospam.please> wrote in message
news:PM********************@comcast.com...
Try inserting:
stream.Seek(0, SeekOrigin.Begin);
"Olav Tollefsen" <x@y.com> wrote in message
news:uQ**************@TK2MSFTNGP12.phx.gbl...
I'm using the following code to create an Xml document to be saved by
the browser (IE):

MemoryStream stream = new MemoryStream();
OrderManager.ExportToXml(stream); // Creates
Xml by using XmlTextWriter to the stream

Response.Clear();
Response.AppendHeader("Content-Disposition", "attachment;
filename=BaldrianOrdersMamut.xml");
Response.BinaryWrite(stream.GetBuffer());
Response.End();

This is a sample of the saved Xml file:

<?xml version="1.0" encoding="utf-8"?>
<GBAOX10>
<ORDERLIST />
</GBAOX10>

The problem is that the resulting file that is saved doesn't seem 100%
right. When you read the content in Notepad it looks OK, but IE have a
problem displaying and show an error like this:

"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.

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

Invalid at the top level of the document. Error processing resource
'file:///C:/Documents and Settings/olavt.SAFARI/My Docu...

</GBAOX10>"

If I just do a File->Save in Notepad overwriting the original file, the
problem disappears.

How can I get the file to save correctly in the first place?

Olav



Nov 12 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Keith Dewell | last post: by
15 posts views Thread by Ken Allen | last post: by
5 posts views Thread by IkBenHet | last post: by
13 posts views Thread by Lee Newson | last post: by
2 posts views Thread by key9 | last post: by
4 posts views Thread by Salad | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.