Page 1 of 1

Beginner struggling with PHP & XML DOM

Posted: Thu Mar 19, 2009 1:43 pm
by kristo5747
Hi

Please forgive me if I am posting to the wrong forum. I am new to PHP and I need help.

I am trying to read this XML file (`myfile.xml`) using DOM:

Code: Select all

<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
I created a very simple PHP document I called `xml_01.php`:

Code: Select all

<?php
$xmlDoc = new DOMDocument();
$xmlDoc->load("myfile.xml");
print $xmlDoc->saveXML();
?>
When I point my browser to http://localhost/xml_01.php, nothing happens. No errors, nothing. I also specified the full path to my XML data file: no change. I even tried re-install the RPM for PHP&XML : no change.

I know I am doing something wrong: is it the code or my configuration? Can someone please help?

My sandbox config is:
RedHat 2.6.9 el
Apache 2.2.3
PHP 5.16
MySQL 5.0

Thanks.

Al.

Re: Beginner struggling with PHP & XML DOM

Posted: Thu Mar 19, 2009 9:15 pm
by rcastera
Hey Al,

Hope I can help you out. Try this:

Code: Select all

 
<?php
    $xmlDoc = new DOMDocument();
    $xmlDoc->load("myfile.xml");
    header("Content-type: text/xml");
    print $xmlDoc->saveXML();
?>
 

Re: Beginner struggling with PHP & XML DOM

Posted: Fri Mar 20, 2009 12:23 pm
by kristo5747
rcastera wrote:Hey Al,

Hope I can help you out. Try this:

Code: Select all

 
<?php
    $xmlDoc = new DOMDocument();
    $xmlDoc->load("myfile.xml");
    header("Content-type: text/xml");
    print $xmlDoc->saveXML();
?>
 
It worked! I am able to read my file.

Thank you!!! :D