我想使用php simplexml解析(一点关键)xml ...但我可以获取属性或任何值... m无法正确解析此XML
<?xml version="1.0" encoding="UTF-8" ?>
<response uri="/crm/private/xml/Leads/getMyRecords">
<result>
<Leads>
<row no="1">
<FL val="LEADID">418176000000051001</FL>
<FL val="SMOWNERID">418176000000047003</FL>
<FL val="Lead Owner"><![CDATA[Amit Patil]]>
</FL>
<FL val="Company"><![CDATA[demo Company]]>
</FL>
<FL val="First Name"><![CDATA[Test]]>
</FL>
<FL val="Last Name"><![CDATA[Demo]]>
</FL>
<FL val="Designation"><![CDATA[Tesing Lead]]>
</FL>
<FL val="No of Employees"><![CDATA[0]]>
</FL>
这就是我的目标
$xml = simplexml_load_file($url);
if($xml != null){
foreach($xml->result->Leads->row as $key=>$row){
foreach($row->FL as $key=>$val){
echo $val.",";
}
}
}
我如何使用simplexml解析此XML,或者可能是其他什么?
答案 0 :(得分:4)
val是FL的一个属性,而不是内容......所以当你使用含糊不清的$ val
时,我不确定你要检索的是什么由于您拥有的代码应该已经显示了每个元素的内容:要检索属性,请使用
foreach($xml->result->Leads->row as $key=>$row){
foreach($row->FL as $key => $value){
echo $value['val']." => ";
echo $value."<br />";
}
}
从您的XML片段中,我们得出:
LEADID => 418176000000051001
SMOWNERID => 418176000000047003
Lead Owner => Amit Patil
Company => demo Company
First Name => Test
Last Name => Demo
Designation => Tesing Lead
No of Employees => 0