php - Simplexml get node by attribute -


i've got xml file:

<?xml version="1.0" ?> <xml> <opis lang="en">my text</opis> <opis lang="cz">my text2</opis> </xml> 

i want "my text2" - node attribute lang "cz":

$xml = simplexml_load_file($filename); $result = $xml->xpath('//xml/opis[@lang="cz"]') 

but instead of value get:

array(1) (   [0] => simplexmlelement object {     @attributes => array(1) (       [lang] => (string) cz     )   } )) 

try using domdocument:

$xml = new domdocument; $xml->load('yourfile'); $xpath = new domxpath($xml);  foreach ($xpath->query('//xml/opis[@lang="cz"]') $rownode) {   echo $rownode->nodevalue; // 'this item' } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -