0

在使用 Ray Wenderlich 的一些指南之前,我已经完成了 xml 解析,但这些通常适用于涉及多个项目的情况。我正在让一个应用程序简单地显示给定时间的天气状况,并且提要的 XML 只是检查时间的条件。这是有问题的提要:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
        <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
            <channel>

<title>Yahoo! Weather - Montgomery, AL</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Montgomery__AL/*http://weather.yahoo.com/forecast/USAL0375_f.html</link>
<description>Yahoo! Weather for Montgomery, AL</description>
<language>en-us</language>
<lastBuildDate>Thu, 03 Jan 2013 11:55 am CST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Montgomery" region="AL"   country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="43"   direction="0"   speed="5" />
<yweather:atmosphere humidity="66"  visibility="10"  pressure="30.26"  rising="2" />
<yweather:astronomy sunrise="6:46 am"   sunset="4:52 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif</url>
</image>
<item>
<title>Conditions for Montgomery, AL at 11:55 am CST</title>
<geo:lat>32.38</geo:lat>
<geo:long>-86.3</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Montgomery__AL/*http://weather.yahoo.com/forecast/USAL0375_f.html</link>
<pubDate>Thu, 03 Jan 2013 11:55 am CST</pubDate>
<yweather:condition  text="Mostly Cloudy"  code="28"  temp="46"  date="Thu, 03 Jan 2013 11:55 am CST" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 46 F<BR />
<BR /><b>Forecast:</b><BR />
Thu - Partly Cloudy. High: 50 Low: 31<br />
Fri - Sunny. High: 57 Low: 35<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Montgomery__AL/*http://weather.yahoo.com/forecast/USAL0375_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Thu" date="3 Jan 2013" low="31" high="50" text="Partly Cloudy" code="30" />
<yweather:forecast day="Fri" date="4 Jan 2013" low="35" high="57" text="Sunny" code="32" />
<guid isPermaLink="false">USAL0375_2013_01_04_7_00_CST</guid>
</item>
</channel>
</rss>

基本上,我对应用程序只需要当前的温度和条件,它们在 item 标签下包含在 yweather:conditions 标签中。使用 GDataXML,获取此信息并设置 NSString 等于它的最简单方法是什么?

现在,我正在使用 Ray 的教程中的一些复杂的东西,包括 asihttprequest 和 blocks 用于排序并将其全部放入 NSMutableArray,但我相当肯定它现在不需要那么复杂。

4

1 回答 1

0

我喜欢直接解析的 TBXML:http ://www.tbxml.co.uk/TBXML/TBXML_Free.html 。

于 2013-01-03T21:21:41.527 回答