Page 1 of 1

Generating xml with php to use xslt client side

Posted: Tue Sep 06, 2005 1:11 pm
by Jack Williard
I am trying to generate xml that will be processed client side with an associated xslt template. My php generates well-formed xml and if I manually copy and paste the ouput to an .xml file, it generates xhtml properly. However, when the php is accessed directly, I get this error:
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/jwilliard/My Documen...

<?xml-stylesheet type='text/xsl' href='./as.xslt'?>";
---------------------------------------------------^
Researching the problem, I noticed this at w3schools.com:
Generating XML with ASP
XML can be generated on a server without any installed XML software.

To generate an XML response from the server - simply write the following code and save it as an ASP file on the web server:

<%
response.ContentType="text/xml"
response.Write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.Write("<note>")
response.Write("<from>Jani</from>")
response.Write("<to>Tove</to>")
response.Write("<message>Remember me this weekend</message>")
response.Write("</note>")
%>

Note that the content type of the response must be set to "text/xml".

How do I set the content type in php? Is this my problem?

Thank you huge for any help.

Posted: Tue Sep 06, 2005 1:29 pm
by feyd
the header() function is used to set the content-type of the page.

(remember to place the call before any output is sent to the browser (via php or not)

Posted: Tue Sep 06, 2005 4:13 pm
by timvw
If you accessing the file through your filesystem..(resource 'file:///C:/Documents and Settings/jwilliard/My Documen... ) the script will not be parsed..

If you have static XML and XSL files, it's possible to have an XSLT process.. Just search this forum on XML XSL as we've talked about this last weekend or so.