Извлечение конкретного атрибута из XML api
Я пытаюсь извлечь и распечатать raw_text из xml API с помощью Jquery.
Я успешно запустить AJAX-вызов, чтобы вызвать API-интерфейс .
<pre><response xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2" xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd"> <request_index>84211629</request_index> <data_source name="metars"/> <request type="retrieve"/> <errors/> <warnings/> <time_taken_ms>5</time_taken_ms> <data num_results="6"> <METAR> <raw_text> KDEN 141753Z 36022G34KT 10SM FEW080 SCT130 BKN180 M02/M08 A3011 RMK AO2 PK WND 35036/1703 SLP217 60000 T10221083 11022 21039 51023 </raw_text> <station_id>KDEN</station_id> <observation_time>2019-03-14T17:53:00Z</observation_time> <latitude>39.85</latitude> <longitude>-104.65</longitude> <temp_c>-2.2</temp_c> <dewpoint_c>-8.3</dewpoint_c> <wind_dir_degrees>360</wind_dir_degrees> <wind_speed_kt>22</wind_speed_kt> <wind_gust_kt>34</wind_gust_kt> <visibility_statute_mi>10.0</visibility_statute_mi> <altim_in_hg>30.109253</altim_in_hg> <sea_level_pressure_mb>1021.7</sea_level_pressure_mb> <quality_control_flags> <auto_station>TRUE</auto_station> </quality_control_flags> <sky_condition sky_cover="FEW" cloud_base_ft_agl="8000"/> <sky_condition sky_cover="SCT" cloud_base_ft_agl="13000"/> <sky_condition sky_cover="BKN" cloud_base_ft_agl="18000"/> <flight_category>VFR</flight_category> <three_hr_pressure_tendency_mb>2.3</three_hr_pressure_tendency_mb> <maxT_c>-2.2</maxT_c> <minT_c>-3.9</minT_c> <pcp6hr_in>0.005</pcp6hr_in> <metar_type>METAR</metar_type> <elevation_m>1640.0</elevation_m> </METAR>
Что я уже пробовал:
ow i am trying to get a value of raw_text. <pre lang="Javascript">$.ajax({ type: "GET", url: "https://www.aviationweather.gov/adds/dataserver_current/httpparam", dataType: "xml", data: { dataSource:dataSource, requestType:requestType, format:format, stationString:stationString, hoursBeforeNow:hoursBeforeNow }, success: function(data) { //remainder of the code console.log(data); console.log(data.METAR.raw_text) // not able to get this value } }); });