回显简单的xml对象

时间:2017-02-16 08:37:43

标签: php xml

我能够解析并显示xml文件中的第一个对象但是无法回显第二个对象。

这是我获得的结果

noaa\weather\response\CurrentWeather Object
(
    [xml:protected] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [version] => 1.2
                )

            [request_index] => 664770430
            [data_source] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [name] => metars
                        )

                )

            [request] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [type] => retrieve
                        )

                )

            [errors] => SimpleXMLElement Object
                (
                )

            [warnings] => SimpleXMLElement Object
                (
                )

            [time_taken_ms] => 4
            [data] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [num_results] => 4
                        )

                    [METAR] => Array
                        (
                            [0] => SimpleXMLElement Object
                                (
                                    [raw_text] => EGGW 160750Z 21006KT 3400 BR SCT001 BKN003 05/05 Q1029
                                    [station_id] => EGGW
                                    [observation_time] => 2017-02-16T07:50:00Z
                                    [latitude] => 51.87
                                    [longitude] => -0.37
                                    [temp_c] => 5.0
                                    [dewpoint_c] => 5.0
                                    [wind_dir_degrees] => 210
                                    [wind_speed_kt] => 6
                                    [visibility_statute_mi] => 2.11
                                    [altim_in_hg] => 30.383858
                                    [wx_string] => BR
                                    [sky_condition] => Array
                                        (
                                            [0] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [sky_cover] => SCT
                                                            [cloud_base_ft_agl] => 100
                                                        )

                                                )

                                            [1] => SimpleXMLElement Object
                                                (
                                                    [@attributes] => Array
                                                        (
                                                            [sky_cover] => BKN
                                                            [cloud_base_ft_agl] => 300
                                                        )

                                                )

                                        )

                                    [flight_category] => LIFR
                                    [metar_type] => METAR
                                    [elevation_m] => 160.0
                                )

                            [1] => SimpleXMLElement Object
                                (
                                    [raw_text] => EGNV 160750Z 21015KT 9999 SCT040 07/04 Q1023
                                    [station_id] => EGNV
                                    [observation_time] => 2017-02-16T07:50:00Z
                                    [latitude] => 54.52
                                    [longitude] => -1.42
                                    [temp_c] => 7.0
                                    [dewpoint_c] => 4.0
                                    [wind_dir_degrees] => 210
                                    [wind_speed_kt] => 15
                                    [visibility_statute_mi] => 6.21
                                    [altim_in_hg] => 30.206694
                                    [sky_condition] => SimpleXMLElement Object
                                        (
                                            [@attributes] => Array
                                                (
                                                    [sky_cover] => SCT
                                                    [cloud_base_ft_agl] => 4000
                                                )

                                        )

                                    [flight_category] => VFR
                                    [metar_type] => METAR
                                    [elevation_m] => 37.0
                                )    

                     )

        )

    [cachedValues:protected] => Array
        (
            [location] => 
            [observation_time] => 2017-02-16T07:50:00Z
            [temp_f] => 
            [dewpoint_f] => 
            [relative_humidity] => 
            [wind_string] => 
            [weather] => 
            [raw_text] => EGGW 160750Z 21006KT 3400 BR SCT001 BKN003 05/05 Q1029
            [station_id] => EGGW
            [flight_category] => LIFR
            [latitude] => 51.87
            [longitude] => -0.37
            [temp_c] => 5.0
            [dewpoint_c] => 5.0
            [wind_dir_degrees] => 210
            [wind_speed_kt] => 6
            [visibility_statute_mi] => 2.11
            [altim_in_hg] => 30.383858
            [wx_string] => BR
            [sky_condition] => 
            [elevation_m] => 160.0
        )

    [cachedValues2] => Array
        (
            [location] => 
            [observation_time] => 2017-02-16T07:50:00Z
            [temp_f] => 
            [dewpoint_f] => 
            [relative_humidity] => 
            [wind_string] => 
            [weather] => 
            [raw_text] => EGNV 160750Z 21015KT 9999 SCT040 07/04 Q1023
            [station_id] => EGNV
            [flight_category] => VFR
            [latitude] => 54.52
            [longitude] => -1.42
            [temp_c] => 7.0
            [dewpoint_c] => 4.0
            [wind_dir_degrees] => 210
            [wind_speed_kt] => 15
            [visibility_statute_mi] => 6.21
            [altim_in_hg] => 30.206694
            [wx_string] => BR
            [sky_condition] => 
            [elevation_m] => 37.0
        )

)

以下是我用来回显第一个对象的代码的部分示例。哪个工作正常。

echo "Metar: " . $current->getRawF(). "\n";
echo "<hr>";
echo "<br>";
echo "Station ID: " . $current->getStationId() . '&nbsp;&nbsp;(' . $current->getCat() .")" ;

无论我尝试过什么,我都能够回应任何第二个对象(egnv)。我希望得到一些帮助,指出我正确的方向。 谢谢您的帮助 史蒂夫

0 个答案:

没有答案