Parse XML with Namespace using SimpleXML

前端 未结 6 956
独厮守ぢ
独厮守ぢ 2020-11-21 23:45

I have this as xml:


    
        &         


        
6条回答
  •  清酒与你
    2020-11-22 00:47

    Another approach is to use SimpleXML for parsing and DOMDocument for manipulation/access, which bypasses namespacing issues altogether:

    $xml = new SimpleXMLElement($r);
    $xml = dom_import_simplexml($xml);
    $nodelist= $xml->getElementsByTagName('event');  
    for($i = 0; $i < $nodelist->length; $i++) {
        $sessions = $nodelist->item($i)->getElementsByTagName('sessionKey');
        echo $sessions->item(0)->nodeValue;
    }
    

提交回复
热议问题