handling XML sent via http:

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
greynolds
Forum Newbie
Posts: 1
Joined: Sat Feb 25, 2012 12:44 pm

handling XML sent via http:

Post by greynolds »

Hi,
I’m trying to write a PHP page that receives XML from a remote sever (triggered by a third party event such as a message being sent to the server.) Thus, I am not querying a server and processing a response, but rather waiting for a unsolicited (but not unwelcome) call to my page.

If I have the XML in a local file, I can process the XML just fine with:
$url = 'xml-file.xml';
$xml = simplexml_load_file($url);

Btw the xml in the file looks like:

<?xml version="1.0" encoding="UTF-8"?>
<ALERTSERVICE>
<PHONENUMBER>1234567890</PHONENUMBER>
<KEYWORD>Traffic</KEYWORD>
<CONTENTS>Route 42</CONTENTS>
</ ALERTSERVICE >

Can anyone provide with the code substitution for when the same XML is contained in the HTTP, like this:
http://www.some_server.com/process_test/process.php?xml=<?xml version="1.0" encoding="UTF-8"?><ALERTSERVICE><PHONENUMBER>1234567890</PHONENUMBER><KEYWORD>traffic</KEYWORD><CONTENTS>Route 42</CONTENTS></ALERTSERVICE>

I have the feeling that I’m missing something totally obvious, but have been fruitlessly searching and experimenting, up against a deadline. Thanks in advance for your help!
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: handling XML sent via http:

Post by Eric! »

This seems a bit sketchy to be passing XML in the URL query, but this is how you would get the xml in your example

Code: Select all

$xml=$_GET['xml']; // read into a string ... you might want to filter this string some depending on what you are doing with it
//now convert it to an xml object and process it.
You might need to urldecode() it too...
Post Reply