This is my xml data.
<?xml version="1.0" encoding="UTF-8"?>
<ns1:catalog
xmlns:ns1="http://www.omnichannelintegrationlayer.com/xml/catalog/2016-01-01" catalog-id="at-master-catalog">
<ns1:product product-id="4132002004">
<ns1:min-order-quantity>1</ns1:min-order-quantity>
<ns1:step-quantity>1</ns1:step-quantity>
<ns1:short-description
xmlns:ns2="xml" ns2:lang="de-AT">Jogginghose Cacy jr
</ns1:short-description>
<ns1:short-description
xmlns:ns2="xml" ns2:lang="de-CH">Jogginghose Cacy jr
</ns1:short-description>
</ns1:product>
I'm trying to filter the xml the short-description base on ns2:lang attribute.
This is what I've done so far:
foreach ($xml->xpath("//ns1:product[@product-id='".$productid."']/ns1:short-description/") as $short_description) {
$namespaces = $short_description->getNameSpaces(true);
$ns1 = $short_description->children($namespaces['ns1']);
$ns2 = $short_description->children($namespaces['ns2']);
var_dump($ns2);
echo $ns2["lang"];
}
The output of var_dump looks okay:
object(SimpleXMLElement)#27 (1) { ["@attributes"]=> array(1) { ["lang"]=> string(5) "de-AT" } }
But I can't access the array because when I echo $ns2["lang"], I'm getting NULL.
I already tried different solution like declaring namespace first but no luck.
Thanks in advance.
->attributes()?short-description- what are you expecting your xpath expression to match?