<info id="12AB" conf="D4XD">
<cinfo code="CB">Consumer Business</cinfo>
<cinfo code="EB">Enterprise Business</cinfo>
</info>
如何遍历cinfo元素,我可以读取值,即消费者业务和属性值,即CB?
$obj = new SimpleXMLElement($xmldata);
foreach ($obj->children() as $cinfos) {
?????
}
答案 0 :(得分:1)
This应该这样做:
$obj = new SimpleXMLElement($xml);
foreach ($obj->cinfo as $cinfos) {
// This is the value
$val = $cinfos[0];
echo $val."\r\n";;
// Iterate through the attributes
foreach($cinfos[0]->attributes() as $key => $val) {
echo $key,'="',$val,"\"\n";
}
}