Beginner struggling with PHP & XML DOM

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kristo5747
Forum Newbie
Posts: 2
Joined: Thu Mar 19, 2009 11:44 am

Beginner struggling with PHP & XML DOM

Post 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.
rcastera
Forum Newbie
Posts: 4
Joined: Wed Mar 11, 2009 8:07 pm

Re: Beginner struggling with PHP & XML DOM

Post 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();
?>
 
kristo5747
Forum Newbie
Posts: 2
Joined: Thu Mar 19, 2009 11:44 am

Re: Beginner struggling with PHP & XML DOM

Post 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
Post Reply