ばかげているように見える問題を解決しようとしているので、その投稿を書いていますが、残念ながら解決できません。simplexml_load_file($link)
以下のように解析する XML ファイル (リンク) があります。
function getListPoints($countryCode,$nbrPoints)
{
$xml_containt_url = "http://openchargemap.org/api/?output=xml&countrycode=".$countryCode."&maxresults=".$nbrPoints;
$xml_output = simplexml_load_file($xml_containt_url);
return $xml_output;
}
したがって、xml出力を印刷すると:
$infos_point = getListPoints("US",2);
print($infos_point);
私は私が望むすべてを手に入れます、それは私に与えます:
SimpleXMLElement Object
(
[ChargePoint] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[ID] => 2381
[UUID] => BFE199D5-07D4-4310-86D7-8BCB9092541D
[DateLastConfirmed] => 31/08/2010 00:00:00
[OperatorID] => 1
[OperatorTitle] => (Unknown Operator)
[DataProviderID] => 2
[NumberOfPoints] =>
[DataQualityLevel] => 1
[PercentageSimilarity] =>
)
[GeneralComments] => 1 SP Inductive
[AddressInfo] => SimpleXMLElement Object
(
[LocationTitle] => Sacramento County Public Garage
[AddressLine1] => 725 7th St
[AddressLine2] => SimpleXMLElement Object
(
)
[Town] => Sacramento
[StateOrProvince] => CA
[Postcode] => 95814
[Country] => United States
[Latitude] => 38.5846
[Longitude] => -121.4961
[ContactTelephone1] => 916-874-6227
[AccessComments] => 24 hours daily; pay lot
[RelatedURL] => SimpleXMLElement Object
(
)
)
問題は、SimpleXMLElement オブジェクトの値を取得したいときに発生します。たとえば、Town の値を取得したいので、次のように進めます。
$Town = $infos_point->ChargePoint[0]->AdressInfo->Town;
print($Town);
そして、それは私に空白のページを与えます。インターネットで読んだことはすべて試しましたが、まだ何もしていません。多分誰かが何が起こっているのか教えてくれますか? プロジェクトを継続できるのは素晴らしいことです。