I want to parse (little critical) xml using php simplexml…But i can aither get attribute or either value…m not able to parse this XML properly
<?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>
And this is what i am soo far
$xml = simplexml_load_file($url);
if($xml != null){
foreach($xml->result->Leads->row as $key=>$row){
foreach($row->FL as $key=>$val){
echo $val.",";
}
}
}
How can i parse this XML using simplexml or may be something else ??
val is an attributeof FL, not the content… so I’m not sure what you’re trying to retrieve when you use the ambiguously named $val
As the code you have should already display the content of each element: to retrieve the attributes, use
From your snippet of XML, this gives: