<?xml version="1.0" encoding="utf-8" ?> <items> <aaa> </aaa> <aaa> </aaa> <aaa> <bbb> </bbb> <bbb> </bbb> <bbb> <ccc> Only this childnod what I need </ccc> <ccc> And this one </ccc> </bbb> </aaa> </items>
我想用PHP解析上面给出的XML.我不知道如何获得这两个子节点.
当我使用下面的代码时,它会触发错误:警告:main()[function.main]:当只有0个这样的元素存在时,不能添加元素bbb编号2
<?PHP header('Content-type:text/html; charset=utf-8'); $xml = simplexml_load_file('2.xml'); foreach ($xml->aaa[2]->bbb as $bbb){ echo $bbb[2]->$ccc; // wrong in here echo $bbb[3]->$ccc; } ?>