Reading XML with PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
First of all I want to say I do not have very clear understanding of
XML and PHP and what you can do with those two.
Now the problem I have is:
There is that booking company that sends data to me via XML and I have
in my server to read that XML and store it in a DB.
What I have no Idea how to do is read that XML.
To start with, I though they were using $_POST to upload an XML file,
but it seems they do not as when I get a request in my script I
print_r the $_POST and it is empty. The same with $_GET, empty.

Do you have any idea of other ways that they might send the XML data
and how can I read them with a PHP4 script?

Thank you.

Re: Reading XML with PHP

Am 16 Mar 2007 02:47:32 -0700 schrieb Aggelos:

Quoted text here. Click to load it

Hello Aggelos!

First of all, a short tutorial about uploading (sending it to your server)
files with PHP can be found there:

When the file is stored on the server you can read it as usual with fopen,
fread, fclose etc.

Of course, if you want to parse the XML file that's a bit more complicated.
I suggest you to look for a class on

A very good class that is also used by Joomla and Mambo CMS (among others)
is DOMIT! XML Parser by John Heinstein:

Good luck.

 ~ MK

Re: Reading XML with PHP

Quoted text here. Click to load it
THank you but my problem was that they do not do a $_FILE post, just a
$_POST of an XML string...
ANd I caught that via $HTTP_RAW_POST_DATA.

Thanks for the parsing class tip though ;)

Re: Reading XML with PHP

OK Sollution to the problem found !!!
ALl the data were coming to the following variable, and that's why I
couldn't read them VIA $_POST

If you have any comments or suggestions,  I will be happy to read
them :)

THank you.

Re: Reading XML with PHP

Quoted text here. Click to load it

Could be that they're sending you an XML-file rather then 'just' XML, then  
it would be in the $_FILES array.

Also, reading php://input can be very handy to determine what the exact  
request was you received.
Rik Wasmus

Site Timeline