On 04/12/2013 01:01 PM, gaëlle fernandez wrote:
> Hello everyone!!
>
> I'm working on a way to draw some chart with climate datas, and i'm only
> at the first step : parsing the xml given by the api.
>
> *What i've already done :*
> /(This xml whose content is copied in the file i give you)/
>
> *As you can see, the first children of <list> is
> <domain.web.AnnualGcmDatum>*
>
> Then, i use a SimpleXMLElement to parse the xml :
>
> $fichier =
> "
http://climatedataapi.worldbank.org/climateweb/rest/v1/country/annualavg/pr/".$firstYear."/".$lastYear."/".$countryIso.".xml";
> $curl = curl_init();
> curl_setopt($curl,CURLOPT_URL,$fichier);
> curl_setopt($curl,CURLOPT_RETURNTRANSFER,true); //récupère le
> contenu sous forme de chaine
> $contenu = curl_exec($curl);
> $xml = new SimpleXMLElement($contenu);
> foreach($xml->domain.web.AnnualGcmDatum as $v){
> echo '<li>'.$v->annualData.'</li>';
> }
>
>
> *BUT*, because of the strange name of the node, php does not understand
> what i want to do.
>
> Maybe i've done something wrong, so please tell me my mistake, this
> could help me go further.
>
> Thanks by advance
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "World Bank API" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
world-bank-ap...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>
Hi Gaëlle,
There is nothing strange or wrong about the node name (see [1]).
What you have to resolve is proper way to access XML nodes with the PHP
library that you are using. I may be wrong, but I think that's outside
of the scope of this mailing list. I would however suggest that use use
SimpleXMLElement::xpath or something like
$xml->{'domain.web.AnnualGcmDatum'}.
[1]
http://www.w3.org/TR/REC-xml/#sec-common-syn
-Sarven
http://csarven.ca/#i