object(SimpleXMLElement)访问值

时间:2016-04-14 15:07:28

标签: php xml

Bellow是$ xml结果集。我可以访问密钥"数据集"使用$ xml ['数据集']但我需要访问密钥"数据"而且我不能。任何人都可以帮我解决这个问题吗?

object(SimpleXMLElement)#17 (2) { ["@attributes"]=> array(1) { ["dataset"]=> string(101) "/DATOSRED/NUMERICO/PRODUCTOS/WRF/WRF_ARW_1KM_2D/20160414/wrf_arw_det1km_history_d06_20160414_0000.nc4" } ["point"]=> object(SimpleXMLElement)#18 (1) { ["data"]=> array(9) { [0]=> string(20) "2016-04-14T15:00:00Z" [1]=> string(5) "41.15" [2]=> string(10) "-8.6166667" [3]=> string(17) "289.3196105957031" [4]=> string(3) "0.0" [5]=> string(17) "3.244610071182251" [6]=> string(17) "3.326730728149414" [7]=> string(18) "224.28402709960938" [8]=> string(13) "24111.9921875" } } }

1 个答案:

答案 0 :(得分:1)

object(SimpleXMLElement)#17 (2) { 
    ["@attributes"]=> array(1) {
         ["dataset"]=> string(101) "/DATOSRED/NUMERICO/PRODUCTOS/WRF/WRF_ARW_1KM_2D/20160414/wrf_arw_det1km_history_d06_20160414_0000.nc4"
     }
     ["point"]=> object(SimpleXMLElement)#18 (1) {
         ["data"]=> array(9) {
             [0]=> string(20) "2016-04-14T15:00:00Z"
             [1]=> string(5) "41.15"
             [2]=> string(10) "-8.6166667"
             [3]=> string(17) "289.3196105957031" 
             [4]=> string(3) "0.0"
             [5]=> string(17) "3.244610071182251"
             [6]=> string(17) "3.326730728149414"
             [7]=> string(18) "224.28402709960938"
             [8]=> string(13) "24111.9921875"
        }
    }
 }

如果格式化onject,则可以看到数组数据嵌套在对象点内。所以你需要做

$xml->point->data

获取数据。