0

I have an xml file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
  <epp xmlns="urn:ietf:params:xml:ns:epp-1.0">
    <response>
    <result code="1000">
      <msg lang="nl">De transactie is succesvol afgerond.</msg>
    </result>
    <trID>
      <clTRID>300100</clTRID>
      <svTRID>602C9E44-3F79-564D-5A53-C9689F088A1C</svTRID>
    </trID>
  </response>
</epp>

I need the result code from the xml in a string. I already tried it with simpleXml :

$resCode = new \SimpleXMLElement($info);
$text = (string)$resCode->result;`

my xml is stored in $info

But this is not working. What am I doing wrong?

yedpodtrzitko
  • 9,035
  • 2
  • 40
  • 42
Tommie
  • 348
  • 1
  • 4
  • 12

1 Answers1

0

Your XML path is completely off. Try this according to the xml you posted:

$text = (string)$resCode->response->result["code"];

(Hint: the first node "epp" is not needed as it is the root node. So your path starts from inside this root node.)

Some samples: http://www.php.net/manual/en/simplexml.examples-basic.php

ToBe
  • 2,667
  • 1
  • 18
  • 30