3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml = '<?xml version="1.0"?> <xdm:Device xmlns:xdm="http://www.hp.com/schemas/imaging/con/xdm/1.1/" xmlns:dd="http://www.hp.com/schemas/imaging/con/dictionaries/1.0/" xmlns:bsi="http://www.hp.com/schemas/imaging/con/bsi/2003/08/21" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:count="http://www.hp.com/schemas/imaging/con/counter/2006/01/13" xmlns:media="http://www.hp.com/schemas/imaging/con/media/2006/01/13/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tt="http://www.hp.com/schemas/imaging/con/capabilities/1.1/" xmlns:pwg="http://www.hp.com/schemas/imaging/con/pwg/sm/1.0/"> <xdm:Information> <xdm:Component id="system" componentType="system"> <dd:MakeAndModel>Samsung LaserJet ML220</dd:MakeAndModel> <dd:Description>Blackand while printer</dd:Description> <dd:ProductNumber>XB3zzz</dd:ProductNumber> <dd:Manufacturer> <dd:Name>Samsung</dd:Name> </dd:Manufacturer> </xdm:Component> </xdm:Information> </xdm:Device>'; // Defining my own ways of referring to the namespaces, regardless of prefix used define('XMLNS_HP_XDM_1_1', 'http://www.hp.com/schemas/imaging/con/xdm/1.1/'); define('XMLNS_HP_DICT_1_0', 'http://www.hp.com/schemas/imaging/con/dictionaries/1.0/'); // Load the XML in the normal way $sx = simplexml_load_string($xml); // Switch to the first namespace, and look at the first Component $component = $sx->children(XMLNS_HP_XDM_1_1)->Information->Component; $component_id = (string)$component->attributes(null)->id; // Switch to the second namespace to find the MakeAndModel $make_and_model = (string)$component->children(XMLNS_HP_DICT_1_0)->MakeAndModel; echo "$component_id : $make_and_model";

preferences:
170.66 ms | 405 KiB | 5 Q