Automator - 将 URL 中的 XML 解析为变量(或字典)
第一篇文章在这里!
我知道如何编写一些代码,但请把我视为一个完全的新手。
我正在尝试执行一个 Automator 操作(Mac),从 URL(URL 永远不会改变)读取 XML 并解析它。
XML 包含大量数据,但我感兴趣的是两个特定值:“名称”和特定于该名称的存储的“URL”。
这是 XML 的示例,如下所示:
<jobs>
<jobad>
<id>54844</id>
<title>HR Manager</title>
<text>Random text</text>
<location>City, State</location>
<expiration/>
<url>https://url/jobs/43395.58958.54844</url>
<application>
https://url/jobs/43395.58958.54844.1
</application>
</jobad>
<jobs>
<jobad>
<id>54847</id>
<title>Sales Manager</title>
<text>Random text</text>
<location>City, State</location>
<expiration/>
<url>https://url/jobs/43395.58958.54847</url>
<application>
https://url/jobs/43395.58958.54847.1
</application>
</jobad>
我不需要大部分信息。我基本上只需要
这个想法是解析 XML,将其添加到字典中,我可以在其中创建一个菜单,显示所有
我尝试以不同的方式解析但失败了,因为我不太了解 applescript。另外,它不一定是字典,任何能完成这项工作的变量都可以。这就是我尝试过的。
我确实已经启动并运行了菜单的代码以及所选项目的返回。
XML 解析让我头疼。
提前致谢!
First post here!
I know how to code a little, but please regard me as a total newb.
I'm trying to do an Automator action (Mac) that reads a XML from a URL (URL never changes) and parses it.
The XML has a lot of data, but my interest is in two specific values, the "Name" and a stored "URL" specific for that name.
This is an example of the XML looks like:
<jobs>
<jobad>
<id>54844</id>
<title>HR Manager</title>
<text>Random text</text>
<location>City, State</location>
<expiration/>
<url>https://url/jobs/43395.58958.54844</url>
<application>
https://url/jobs/43395.58958.54844.1
</application>
</jobad>
<jobs>
<jobad>
<id>54847</id>
<title>Sales Manager</title>
<text>Random text</text>
<location>City, State</location>
<expiration/>
<url>https://url/jobs/43395.58958.54847</url>
<application>
https://url/jobs/43395.58958.54847.1
</application>
</jobad>
I don't need most of the information. I basically just need the <title>
and the <url>
.
The idea is to parse the XML, add it into a dictionary where I can make a menu, that shows all the <title>
values, have the user select which one they want, and return the <url>
of the selected <title>
.
I've tried to parse on different ways but failed because I don't know applescript that well. Also, it doesn't have to be a dictionary, any variable that does the job will do. This is just what I've tried.
I do have the code up and running for the menu and the return of the selected item.
It is the XML parsing that's breaking my head.
Thanks in advace!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,首先,您的示例 XML 格式错误,jobs 标签未关闭。我假设是这样并在桌面上保存为“Jobs.xml”:
脚本可能是:
结果是:
OK then, first, your example XML is malfomed, the jobs tag doesn't close. I assume it's this way and saved on the desktop as "Jobs.xml" :
and the script might be :
the result is :