tags:

views:

20

answers:

1

I'm using a PHP file to output an XML Document.
I'm using a CSS file to format that XML Document.
My browser (Safari) won't show the formatting unless I feed it a file with an xml extension. I thought the header took precedence over the extension.

parser.php (after php processing)

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/css" href="parser.css"?>
<Main>
<Test>This is some test text that should appear in Blue.</Test>
</Main>

parser.css

Main { 
    background-color: gray;
}
Test {
    color: blue;
}

If I save the output of the php file as an xml and view that in the browser, then it properly shows the formatting. But I need to generate the xml on the fly.
Is this expected behavior? I guess I could generate a separate file with php and then forward the browser there.
Or I could tell set my server to parse xml files and then just change the extension of my php file (with all the code in it) to XML. But neither of those seem like they should be necessary.

+2  A: 

The document is being returned as text/html (as that's what your server is sending as the content type header). You'll want to force it to return as XML, which should solve your issue.

// Before you render parser.php...
header('Content-type: text/xml');

This way, regardless of the extension, your browser will know to render it as XML.

Owen
Wonderful. Darn, I wondered if I had a need for "Content-type:". Thanks
Andrew