Separate Xml Attributes In Php
I'm getting the XML attributes for sky_condition from this XML file:
Solution 1:
Just do this
$xmlString = '<METAR>
<sky_condition sky_cover="SCT" cloud_base_ft_agl="1600"/>
<sky_condition sky_cover="BKN" cloud_base_ft_agl="2200"/>
</METAR>
';
$xml = simplexml_load_string($xmlString);
$td = "<tr><td><strong>%s</strong></td><td><strong>%s</strong></td></tr>";
echo'<table>';
foreach ( $xml->sky_condition as$value ) {
$attribute = $value->attributes();
printf($td, $attribute['sky_cover'], $attribute['cloud_base_ft_agl']);
}
echo'</table>';
See Demo
http://codepad.viper-7.com/A9pba4
Post a Comment for "Separate Xml Attributes In Php"