AlistairSKing

Hi

Yes, it's another one of these - sorry but I'm fairly new to this.

I'm getting the following error, when trying to display some XML code on a browser and can't see where I'm going wrong:

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.

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

Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource 'http://localhost:2999/Exam/Exam.aspx'. L...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&..


I'm using the following C# code in the (Page_load of Exam.aspx.cs) to try and display the XML:

string whatever = "<CiscoIPPhoneText>\r\n";
string whatever1 = "<Title>Arrests</Title>\r\n";
string whatever2 = "<Text>C# XML text</Text>\r\n";
string whatever3 = "<SoftKeyItem>\r\n";
string whatever4 = "<Name>Next</Name>\r\n";
string whatever5 = "<URL>http://192.168.10.10/NWP/briefing_sheet/Arrests2.php</URL>\r\n";
string whatever6 = "<Position>1</Position>\r\n";
string whatever7 = "</SoftKeyItem>\r\n";
string whatever8 = "<SoftKeyItem>\r\n";
string whatever9 = "<Name>Exit</Name>\r\n";
string whatever10 = "<URL>http://192.168.10.10/NWP/briefing_sheet/briefing_sheet.php</URL>\r\n";
string whatever11 = "<Position>3</Position>\r\n";
string whatever12 = "</SoftKeyItem>\r\n";
string whatever13 = "</CiscoIPPhoneText>\r";
Response.ClearContent();
Response.ContentType = "text/xml";
Response.Write("< xml version=" + "\"" + "1.0" + "\"" + " >\r\n");
Response.Write(whatever);
Response.Write(whatever1);
Response.Write(whatever2);
Response.Write(whatever3);
Response.Write(whatever4);
Response.Write(whatever5);
Response.Write(whatever6);
Response.Write(whatever7);
Response.Write(whatever8);
Response.Write(whatever9);
Response.Write(whatever10);
Response.Write(whatever11);
Response.Write(whatever12);
Response.Write(whatever13);


....and this is my .aspx code:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Exam.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script type="text/javascript">
function myClose(thetime)
{
// Next statement added to prevent the message "The web page you are viewing is trying to close the window." from
// appearing.
window.opener="anyvalue"
setTimeout("window.close()", thetime)
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Generate XML file with proper text values</title>
</head>

<body onload="myClose('3000')">
<form id="Form1" runat="server">
<div>
&nbsp;
&nbsp;</div>
</form>
</body>
</html>

Can anyone spot my non-deliberate mistake I do not have a XSL or CSS file as I thought the code above would use some default code. Maybe this assumption is wrong

Thanking you for any help.

Alistair



Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

Sergey Dubinets - MSFT

To render XML file (that doesnt refer on stylesheet explicitly) browser use its own (default) XSL stylesheet. (see: http://www.perfectxml.com/articles/xml/XSLTInMSXML.asp)

This stylesheet gives you an error because XML you send to browser is not well-formed.

To see what you actually send to browser you can go to menu and select View | Source. This should start Notepad and show you raw XML text.

If you'd not be able to find the error yourself post this text (or at least the part from the beginning to the DOCTYPE) back to the forum.

Good luck.






Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

texo

You most likely will get this if using ASP.NET 2.0 and the solution is call "Response.End()".




Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

steverg

Thank you so much.

I've been racking my brain trying to figure out why I was receiving, "Cannot have a DOCTYPE declaration outside of a prolog." when I tried to respond back to my posting ASP with some XML.

Response.End() fixed it, right-as-rain.

Now, I'm wondering why. From what I've heard it has something to do with style sheets.

Can you answer why "Response.End()" fixed the problem






Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

Ian Stallings

Just a follow up in case anyone wanders across this post like I did - the error stems from the web form itself throwing html tags in after the xml generation. It will then append this empty html onto the end of your xml, causing an error in IE because the XML is not properly formed.

Solution I removed all of the html tags from the .aspx page itself and only left the page directive at the top. This worked fine.



That is why the response.end solution above works, it ends the response before this html is output.




Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

NP Rudra

That was a hell of an answer. I had the same problem and I used Response.End() and it works just fine. Thanks! guys.

Is there any way that I could define a XSLT like I define a XMLDocument through the code without actually creating a physical copy of the XML document itself

I am trying to create a XSLFO document on the fly using the XMLDocument class. Trying to figure out.






Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

Martin Honnen

The Load method of XslCompiledTransform allows you to pass in an IXPathNavigable so it is certainly possible for instance to build your XSLT stylesheet with an XmlDocument and then pass that to the Load method (as XmlDocument/XmlNode implements IXPathNavigable). Or use XmlWriter to construct the XSLT with a StringWriter or MemoryStream and then read the stylesheet from a string or memory stream.






Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

scyce

thanks Ian

this is the answer that actually made sense to me and got the problem fixed.

thank you very much.





Re: XML and the .NET Framework Cannot have a DOCTYPE declaration outside of a prolog. Error processing resource

anolan

Thx Ian! This one was giving me a head ache. Had some generated html in my aspx. Removed like you said, works fine now! Thx again!