473,383 Members | 1,918 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,383 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 3339
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.