0

I'm developing a website that needs to communicate with the payment service and this is done by them sending an XML file through a post variable to a receiver file that has to be created to get this information.

I'm using this but I cant get it to work right:

$xml_post = file_get_contents('php://input');
$xml=simplexml_load_file($xml_post);
foreach($xml->children() as $child){
       $body .= $child->getName() . ": " . $child . "<br>";
}

I need to get the information into variables. Here is an example of the XML that I need to recieve:

<?xml version='1.0' encoding='ISO-8859-1'?>
<notification>
  <notificationtype>1</notificationtype>
  <operations>
    <operation>
      <type>1</type>
      <id>00214</id>
    </operation>
  </operations>
</notification>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Matias Contreras
  • 442
  • 5
  • 10

1 Answers1

0

Check out this line of code -

$body .= $child->getName() . ": " . $child . "<br>";

you are appending with a .

This code is working fine at my end -

$xml=simplexml_load_file('abc.xml');
foreach($xml->children() as $child){
       echo $body = $child->getName() . ": " . $child . "<br>";
}

abc.xml file contains -

<?xml version='1.0' encoding='ISO-8859-1'?>
<notification>
  <notificationtype>1</notificationtype>
  <operations>
    <operation>
      <type>1</type>
      <id>00214</id>
    </operation>
  </operations>
</notification>

Output-

notificationtype: 1
operations: 

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
swapnesh
  • 26,318
  • 22
  • 94
  • 126
  • :o I echoed the XML that I get from the POST variable and I get this: `Notification= 1 1 00214 ` What should I do in this case? – Matias Contreras Jun 11 '13 at 04:08
  • @MatíasContrerasSelman then ?? is it not working ?? i showed you the tested code..let me know whr exactly is the problem ?? – swapnesh Jun 11 '13 at 04:11
  • I think the problem is "Notification=" I think that the XML is bad formated so I cant parse it properly – Matias Contreras Jun 11 '13 at 04:14
  • @MatíasContrerasSelman No i dont think so..when we are able to iterate it ..so i dont think ..double checked here as well http://www.w3schools.com/dom/dom_validate.asp – swapnesh Jun 11 '13 at 04:17
  • yep, it says that the first line has an error: where it says: `Notification=` Does it have anything to do about how i'm getting it from the posted variable? – Matias Contreras Jun 11 '13 at 04:21
  • @MatíasContrerasSelman your `Notification=` if it is in the output seems problem to me..let me know the case – swapnesh Jun 11 '13 at 04:24
  • Yep. its in the output, is there anyway I can delete that? – Matias Contreras Jun 11 '13 at 04:27
  • @MatíasContrerasSelman yeah u can ..`explode()` the string – swapnesh Jun 11 '13 at 04:31
  • @MatíasContrerasSelman if you face any problem .let me know then – swapnesh Jun 11 '13 at 04:40
  • Well, I haven't been able to solv the problem yet. As the server sends automatic XMLs to my reciver, I can't directly echo the XML so I'm sending it to my email. For some strange reason the only thing I get in my mailbox is `Notification=1100217` Any ideas? – Matias Contreras Jun 11 '13 at 05:03