[Solved] How to extract value from xml to php [closed]


Using SimpleXMLElement() you can get your product data from xml string; ref

// Your xml string
$xmlString = '<?xml version="1.0"?>
<ABCD xmlns="http://abcd.com">
<PRODUCT xmlns="">
 <CNHEADER>
  <CNTRACK>true</CNTRACK>
  <FIELD name="PRODUCTNO" value="Z41346020"/>
  <FIELD name="ProductType" value="DP"/>
  <FIELD name="strProdCode" value="NL1754"/>
 </CNHEADER>
</PRODUCT>
</ABCD>';

$xmlData = new SimpleXMLElement($xmlString);

$productData = [];
foreach ($xmlData->PRODUCT->CNHEADER->FIELD as $productField) {
    $productData[(string)$productField{'name'}] = (string)$productField{'value'};
}

echo "<pre>";
print_r($productData);
exit;

You will get following output

// Output
Array
(
    [PRODUCTNO] => Z41346020
    [ProductType] => DP
    [strProdCode] => NL1754
)

0

solved How to extract value from xml to php [closed]