Retrieving XML values from namespace elements with PHP

前端 未结 2 823
一整个雨季
一整个雨季 2020-12-21 15:13

Please could someone explain how to loop through the tags in this xml in order to echo all the elements with a d: prefix

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-21 15:38

    As in your other question, you could use an approach with xpath:

    $xml = simplexml_load_file($url);
    
    foreach ($xml->entry as $entry) { // loop over the entries
        print_r($entry->xpath('//d:BC_3MONTH')); // gives you the actual BC_3MONTH
        print_r($entry->xpath('//d:Id')); // the actual ID
    }
    

提交回复
热议问题