用Apple脚本解析XML

用Apple脚本解析XML,xml,applescript,automator,Xml,Applescript,Automator,我尝试创建一个自动工作流程,从网站下载图像。 图像的名称在一个xml文件中,我想提取它们,以便创建一个类似url的url 我发现当我有Automator的URL时如何下载图像,但我正在寻找一种解析XML文件的方法,以便提取图像名称并自动生成好的URL 以下是XML文件的一部分: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://w

我尝试创建一个自动工作流程,从网站下载图像。 图像的名称在一个xml文件中,我想提取它们,以便创建一个类似url的url

我发现当我有Automator的URL时如何下载图像,但我正在寻找一种解析XML文件的方法,以便提取图像名称并自动生成好的URL

以下是XML文件的一部分:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Managers</key>
<dict>
    <key>Sophie Barriac</key>
    <dict>
        <key>image</key>
        <string>sophie.png</string>
        <key>Téléphone</key>
        <dict>
            <key>number</key>
            <string>0460046150</string>
            <key>mobile</key>
            <string>0614589665</string>
        </dict>
        <key>Email</key>
        <dict>
            <key>email</key>
            <string>sophie.barriac@cgi.com</string>
        </dict>
    </dict>
    <key>Kevin Berthier</key>
    <dict>
        <key>image</key>
        <string>kevin.png</string>
        <key>Téléphone</key>
        <dict>
            <key>number</key>
            <string>0469646007</string>
        </dict>
        <key>Email</key>
        <dict>
            <key>email</key>
            <string>kevin.berthier@cgi.com</string>
        </dict>
    </dict>
</dict>

管理者
苏菲·巴里亚克
形象
sophie.png
电话
数
0460046150
可移动的
0614589665
电子邮件
电子邮件
索菲。barriac@cgi.com
凯文·伯蒂尔
形象
kevin.png
电话
数
0469646007
电子邮件
电子邮件
凯文。berthier@cgi.com

我看到了一些关于AppleScript的东西,但我对此一无所知。
如何执行此操作?

由于您发布的XML文件是
.plist
文件,因此您可以使用以下内容:

tell application "System Events"
    set plistFile to contents of property list file "PATH TO PLIST FILE"

    set managersPlist to property list item "Managers" of plistFile
    set managers to every property list item of managersPlist

    repeat with manager in managers
        set imageFile to value of property list item "image" of manager
        display dialog imageFile
    end repeat
end tell

这将提取所有
图像
键的值

由于您发布的XML文件是一个
.plist
文件,因此您可以使用以下内容:

tell application "System Events"
    set plistFile to contents of property list file "PATH TO PLIST FILE"

    set managersPlist to property list item "Managers" of plistFile
    set managers to every property list item of managersPlist

    repeat with manager in managers
        set imageFile to value of property list item "image" of manager
        display dialog imageFile
    end repeat
end tell
这将提取所有
图像
键的值