如何使用 AppleScript 获取和解析 XML 文件? [英] How to fetch and parse an XML file using AppleScript?

查看:37
本文介绍了如何使用 AppleScript 获取和解析 XML 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

某个远程服务器上有一个 XML 文件 (http://foo/bar.xml):

There's an XML file on some remote server (http://foo/bar.xml):

<?xml version="1.0" encoding="UTF-8"?> 
<foo> 
  bar
</foo>

如何使用 AppleScript 获取值bar"?

How can I get the value "bar" using AppleScript?

推荐答案

这是我所做的:

set file_tgt to (POSIX path of (path to temporary items)) & "file.xml"
    do shell script "curl -L " & "http://url.com/file.xml" & " -o " & file_tgt
tell application "System Events"
    set file_content to contents of XML file file_tgt
    tell file_content
        set my_value to value of XML element 1
    end tell
end tell

最初我使用URL Access Scripting"应用程序来获取文件,但自从它在 Lion 中被删除后,我切换到纯 curl,它在 Snow Leopard 和 Lion 下都可以使用.

Originally I was using the "URL Access Scripting" app to fetch the file, but since it has been removed in Lion, I switched to pure curl, which works under both Snow Leopard and Lion.

这篇关于如何使用 AppleScript 获取和解析 XML 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆