tags:

views:

47

answers:

3

is there a way to output xml in php without user know that xml render using php ?

+2  A: 

yeah ofcourse.

Use .htaccess to redirect a XML URI to a php file. Output XML through that file.

atif089
A: 

Send a HTTP header:

header("Content-Type: text/xml"); readfile("xmldoc.xml"); exit();

Joel Alejandro
A: 

If your goal is to turn your XML into a readable web page, one option is to use XSLT to transform the XML into HTML. XSLT is a markup language for transforming one XML format into another, or into HTML. You start by writing an XSLT file that contains instructions on what parts of the XML input file get copied into the output file. Then you feed both XML and XSLT into a XSLT processor to get your HTML.

As a PHP programer, you have two XSLT processors available. The first is the XSLT processor built into most every web browser nowadays. You access it by placing an XML instruction at the top of your XML file, telling the browser to use a specified XSLT file to transform your XML doc. Like so...

<?xml-stylesheet href="/my_stylesheet.xsl" type="text/xsl"?>

This places the burden of transforming your XML on the web client.

The second option is to perform the transformation on the server side using PHP 5's build-in XSL library. You'd use it by loading both the XML and XSLT files into their own DOMDocument objects, and creating an XSLTProcessor object. You pass each dom to the XSLT processor and call a function to transform the XML and return a new document (you have a chose of XML string, HTML string or a DOM Object). After that you can either save it out as a file or send it directly to the user.

The PHP manual has a lot of information on using XSLT, including a sample style sheet to get you started.

John ODonnell