473,287 Members | 1,651 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 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 3333
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Keith Dewell | last post by:
Greetings! My current job has brought me back to working in C++ which I haven't used since school days. The solution to my problem may be trivial but I have struggled with it for the last two...
12
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too....
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
8
by: Sarah | last post by:
I need to access some data on a server. I can access it directly using UNC (i.e. \\ComputerName\ShareName\Path\FileName) or using a mapped network drive resource (S:\Path\FileName). Here is my...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
2
by: key9 | last post by:
Hi all on last post I confused on how to organize file of class, ok ,the problem solved : should include class define head on cpp file. but this time ,still link error: strange is I put the...
0
by: anide | last post by:
Hi all I’ve some problem, I’m trying to converting a sorting algorithm from C++ to C#. In C++ I’ve compiled it using MSVC and its working properly, and in C# I’m using .NET Framework 2.0 (Visual...
4
by: Salad | last post by:
I have a situation where some, not all, users get the message "Couldn't find file "F:\AccessApps\AppName.mdw". This file is required for startup". My app the users are attempting to access is...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.