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,372
  • 15
  • 66
  • 132

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
  • 7,625
  • 6
  • 37
  • 56
swapnesh
  • 25,390
  • 22
  • 93
  • 124