1
我正在寫這篇文章,因爲我試圖解決一個似乎很笨的問題,但不幸的是我無法做到這一點。我有我與simplexml_load_file($link)
如下解析XML文件(鏈接):從SimpleXMLElement對象獲取值
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 = $infos_point->ChargePoint[0]->AdressInfo->Town;
print($Town);
它給了我一個空白頁。我已經嘗試了我在互聯網上閱讀的所有內容,但仍然沒有任何結果 也許有人可以告訴我發生了什麼?這將是偉大的,因爲我將能夠繼續我的項目。