3v4l.org

run code in 300+ PHP versions simultaneously
<?php $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> </ns1:catalog> DATA; $xml = simplexml_load_string($xml); $productid = "4132002004"; $namespaces = $xml->getNamespaces(true); foreach ($xml->xpath("//ns1:product[@product-id='".$productid."']/ns1:short-description") as $short_description) { $langAsString = (string)$short_description->attributes($namespaces['ns2'])->lang; echo $langAsString . PHP_EOL; }

preferences:
22.83 ms | 404 KiB | 5 Q