私は、天気予報サイトからデータを取得し、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の解析に関するSOに関するいくつかのチュートリアルと質問を見てきましたが、これに対する解決策を見つけることができなかったようです。どんな方向でも大歓迎です!
ありがとう。