使用 Applescript 获取 xml 属性的值
我想解析 Yahoo! Weather API,我想将这些元素属性保存到变量中以供以后使用:
<yweather:location city="Zebulon" region="NC" country="US"/>
<yweather:astronomy sunrise="6:52 am" sunset="7:39 pm"/>
<yweather:forecast day="Wed" date="7 Apr 2010" low="61" high="96" text="Partly Cloudy" code="29" />
我怎样才能用苹果脚本做到这一点?
所以,
set locationCity to [city]
set locationRegion to [reagion]
set locationCountry to [country]
set astronomySunrise to [sunriseTime]
set astronomySunset to [sunsetTime]
我希望预测位于某种数组中,以便按日期/日期组织它们
I want to parse the Yahoo! Weather API and I want to save these element attributes to variables for later use:
<yweather:location city="Zebulon" region="NC" country="US"/>
<yweather:astronomy sunrise="6:52 am" sunset="7:39 pm"/>
<yweather:forecast day="Wed" date="7 Apr 2010" low="61" high="96" text="Partly Cloudy" code="29" />
How can I do this with applescript?
So,
set locationCity to [city]
set locationRegion to [reagion]
set locationCountry to [country]
set astronomySunrise to [sunriseTime]
set astronomySunset to [sunsetTime]
I want the forcasts to be in an array of some sort to organize them by day/date
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
系统事件有一小部分本机命令可以帮助您解决问题(未经测试):
据我所知,Applescript 的 XML 挂钩对其 XML 非常挑剔,除了“一些不属于系统事件的数据”之外,没有提供太多故障排除方法。预期类型”。
我在其他地方进行 XML 解析,并且在这里推荐同样的方法。如果需要纯Applescript解决方案,我只知道来自Late Night Software的XML工具添加(免费)和Satimage 与其套件捆绑了更复杂的套件< /a> (付费),但我对此没有任何经验。
System Events has a small set of native commands that can get you around (untested):
From what I gather Applescript's XML hooks are very finicky about it's XML and doesn't offer much in the way of troubleshooting other than "some data not of the expected type".
I go elsewhere for my XML parsing and I recommend the same here. If a pure Applescript solution is required, I only know of the XML Tools addition from Late Night Software (free) and Satimage has a more complex set bundled with their suite (paid), but I don't have any experience with either.