php - Retrieving Node Values from XML if it have 1 diff child name and rest are equal -
i had xml file this
<report> <table> <columns> <column name="datetime"/> <column name="userlogin"/> <column name="campaignname"/> <column name="adgroupname"/> <column name="changes"/> </columns> <row datetime="aug 13, 2013 11:56:34 pm" userlogin="hello123" campaignname="search exact parts - 2012 usa" adgroupname="12 volt razor battery" changes="text ad changed status changed enabled paused"/> <row datetime="aug 13, 2013 11:56:34 pm" userlogin="hello123" campaignname="search exact parts - 2012 usa" adgroupname="razor quad battery" changes="text ad changed status changed enabled paused"/> <row datetime="aug 13, 2013 11:56:34 pm" userlogin="hello123" campaignname="search exact parts - 2012 usa" adgroupname="razor quad tires" changes="text ad changed status changed enabled paused"/> <row datetime="aug 13, 2013 11:56:34 pm" userlogin="hello123" campaignname="search exact parts - 2012 usa" adgroupname="razor replacement battery" changes="text ad changed status changed enabled paused"/> <row datetime="aug 13, 2013 11:56:34 pm" userlogin="hello123" campaignname="search exact parts - 2012 usa" adgroupname="razor.com" changes="text ad changed status changed enabled paused"/> </table> </report>
my problem i'm trying read xml file. code wrote is,
foreach($xml->children() $secgen=>$value){ foreach($value->columns->children() $thrgen){ $feilds[] = $thrgen['name']; } $data[] = $value->row['datetime']; }
this code reading first row value ie.," aug 13, 2013 11:56:34 pm "
even tried in possible ways know. cannot retrieve ways in correct way. if 1 can solve problem, thankful.
use xpath
select datetime
attribute of <row>
nodes:
$results = $xml->xpath("//row/@datetime");
see them all:
foreach ($results $result) echo "$result <br />";
Comments
Post a Comment