XML applescript

XML applescript,xml,applescript,weather,Xml,Applescript,Weather,我知道有很多帖子都有这样的标题,但我对applescript是新手,我不懂它们。基本上我想学习XML 然后把温度和风速之类的值放入它们自己的变量中,这样我就可以随心所欲地处理它们了。 这可能吗 谢谢你真的应该发布到目前为止的代码,否则看起来你根本不懂编码,只是在请别人为你工作。 你有两个选择。一种是使用几个XML解析选项之一。但是对于像openweathermap站点上的一些小XML文件应用程序,只需硬编码分隔符即可提取所需内容。这适用于您提出的问题: set xmlString to do s

我知道有很多帖子都有这样的标题,但我对applescript是新手,我不懂它们。基本上我想学习XML 然后把温度和风速之类的值放入它们自己的变量中,这样我就可以随心所欲地处理它们了。 这可能吗


谢谢

你真的应该发布到目前为止的代码,否则看起来你根本不懂编码,只是在请别人为你工作。 你有两个选择。一种是使用几个XML解析选项之一。但是对于像openweathermap站点上的一些小XML文件应用程序,只需硬编码分隔符即可提取所需内容。这适用于您提出的问题:

set xmlString to do shell script "curl 'http://api.openweathermap.org/data/2.5/weather?q=NewYork&mode=xml'"

set otid to AppleScript's text item delimiters

set AppleScript's text item delimiters to "<temperature value=\""
set xmlString to text item 2 of xmlString
set theTemp to word 1 of xmlString

set AppleScript's text item delimiters to "<speed value=\""
set xmlString to text item 2 of xmlString
set AppleScript's text item delimiters to "\""
set theSpeed to text item 1 of xmlString

set AppleScript's text item delimiters to otid

return "Temperature is " & theTemp & " & Speed is " & theSpeed
将xmlString设置为执行shell脚本“curl”http://api.openweathermap.org/data/2.5/weather?q=NewYork&mode=xml'"
将otid设置为AppleScript的文本项分隔符

将AppleScript的文本项分隔符设置为“您不必使用shell脚本来处理AppleScript中的XML,因为它可以以本机方式进行,也不必将其解析为文本,因为AppleScript是面向对象的,您肯定不想使用文本项分隔符进行解析,因为AppleScript没有内置文本处理的原因是有AppleScriptable文本编辑器,您可以使用这些编辑器处理文本。