Applescript XML Parse Header



我在这里和谷歌搜索,并没有什么,所以我希望有人在这里可以帮助我了解如何解析"href="从XML头在下面的例子。

<?xml version="1.0" encoding="UTF-8"?>
<foo version="2" href="/event/189" product="Server">
    <name>The Name</name>
</foo>

这是我所知道的。要解析xml文件中的元素"name",可以执行以下操作:

set source_xml to choose file "Select your xml source"
set posix_source_xml to POSIX path of source_xml
tell application "System Events"
    set xml_file to XML file posix_source_xml
    tell xml_file
        tell XML element "foo"
            set name_value to value of XML element "name"
        end tell
    end tell
end tell

但是我如何在"foo"头中获得"href="的值?我试了一下,没有成功:

set source_xml to choose file "Select your xml source"
set posix_source_xml to POSIX path of source_xml
tell application "System Events"
    set xml_file to XML file posix_source_xml
    tell xml_file
        set foo_value to value of XML element "foo"
    end tell
end tell

即使它能工作,我想它会返回- version="2" href="/event/189" product="Server" -而不仅仅是-/event/189。

对此的任何帮助都将非常感激!

有一个XML attribute属性

从您的示例中获取href:

set href_value to value of XML attribute "href" of XML element "foo"

最新更新