Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get value from xlm response body

After sending a post request to an api I get the following response body:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<header xmlns="mfp:anaf:dgti:spv:respUploadFisier:v1" dateResponse="202211011543" ExecutionStatus="0" index_incarcare="5001131564"/>

I need the index_incarcare value, how can I get it in a variable using php?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can get to that value using xpath – you just have to mind your namespaces:

$str = <<<XML
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<header xmlns="mfp:anaf:dgti:spv:respUploadFisier:v1" dateResponse="202211011543" 
        ExecutionStatus="0" index_incarcare="5001131564"/>
XML;
$data = simplexml_load_string( $str, 'SimpleXMLElement', LIBXML_NOCDATA);
$data->registerXPathNamespace('xxx', "mfp:anaf:dgti:spv:respUploadFisier:v1");

$inca = $data->xpath('//xxx:header/@index_incarcare')[0];
echo $inca;

Output, based on the xml in your question should be

5001131564
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading