我正在使用我的教授提供的示例,该示例从天气预报站点获取数据并解析 XML 文件以在列表中显示天气状况。我的程序类似,但我想检索嵌套在多个节点中的信息,但我不知道如何获取它。这是我正在使用的 XML 文件:
<?xml version="1.0" encoding="UTF-8"?>
<DirectionsResponse>
<status>OK</status>
<route>
<summary>S Street Viaduct</summary>
<leg>
<step>
<travel_mode>DRIVING</travel_mode>
<start_location>
<lat>40.7021400</lat>
<lng>-74.0158200</lng>
</start_location>
<end_location>
<lat>40.7021400</lat>
<lng>-74.0158200</lng>
</end_location>
<polyline>
<points>kslwFzewbM</points>
<levels>B</levels>
</polyline>
<duration>
<value>0</value>
<text>1 min</text>
</duration>
<html_instructions>Head <b>east</b> on <b>S Street Viaduct</b></html_instructions>
<distance>
<value>0</value>
<text>1 ft</text>
</distance>
</step>
<duration>
<value>0</value>
<text>1 min</text>
</duration>
<distance>
<value>0</value>
<text>1 ft</text>
</distance>
<start_location>
<lat>40.7021400</lat>
<lng>-74.0158200</lng>
</start_location>
<end_location>
<lat>40.7021400</lat>
<lng>-74.0158200</lng>
</end_location>
<start_address>S Street Viaduct, New York, NY 10004, USA</start_address>
<end_address>S Street Viaduct, New York, NY 10004, USA</end_address>
</leg>
<copyrights>Map data ©2010 Google, Sanborn</copyrights>
<overview_polyline>
<points>kslwFzewbM</points>
<levels>B</levels>
</overview_polyline>
</route>
</DirectionsResponse>
我真的只对检索“html_instructions”标签中的信息感兴趣,但它嵌套在“route”、“leg”和“step”标签中。我已经看过几个关于解析 XML 的教程和问题,但似乎找不到解决方案。任何方向将不胜感激!
谢谢。