@ 2018-06-20T11:10:17Z <?php
/**
* How to get attribute of node with namespace using SimpleXML?
*
* @link http://stackoverflow.com/q/6576773/367456
*/
$buffer = '<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ns:quoteRS xmlns:ns="http://www.allianz.com/emagin/api/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="1.0"
xsi:schemaLocation="http://www.allianz.com/emagin/bs/common/v1 bs_common_v1.xsd http://www.allianz.com/emagin/bs/quote/v1 bs_quote_v1.xsd http://www.allianz.com/emagin/bs/domain/travel/v1 bs_domain_travel_v1.xsd">
<ns:status code="ERROR"/>
<ns:messages>
<ns:message code="NO_PRODUCT_AVAILABLE" lang="en" level="info">No offer matching the quotation request.</ns:message>
</ns:messages>
</ns:quoteRS>';
$xml = new SimpleXMLElement($buffer);
print_r($xml);
echo "ibxml version: ", LIBXML_DOTTED_VERSION, "\n";
foreach ($xml->entry as $item)
{
//original comment: how to get seconds?
$namespaces = $item->getNameSpaces(true);
$yt = $item->children($namespaces['yt']);
$seconds = $yt->duration->attributes();
echo $seconds['seconds'], "\n"; // original comment: but doesn't work.
}
echo "done. should read 1870 one time.\n";
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 7.1.0 - 7.1.25 , 7.2.0 - 7.2.33 , 7.3.0 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.4 , 8.3.6 SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 1.0
)
)
ibxml version: 2.9.4
done. should read 1870 one time.
Output for 8.3.5 Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 1.0
)
)
ibxml version: 2.9.4
done. should read 1870 one time.
preferences:dark mode live preview
146.52 ms | 402 KiB | 172 Q