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?
>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