如何从 Applescript 中的字符串(不是文件)创建 XML?

How to create XML from a string (not a file) in Applescript?

我有一个 Applescript,它接收 XML 字符串格式作为参数,我想要 read/parse 数据。收到的字符串如下所示:

<?xml version="1.0" encoding="utf-8" ?>
  <win>
  <name>Documents</name>
  <target>SSD:Documents:</target>
  <listview>1</listview>
  <sidebar>0</sidebar>
  <bounds>1200, 630, 1825, 1080</bounds>
</win>

我看到了 XML 个文件的示例,但我不知道如何根据接收到的字符串填充记录。最终记录可能是这样的:

set myRecord to {name:_XML_element_name_, tg:_XML_element_target_, listview: ...}

或者我至少可以使用一些变量:

set theName to _XML_element_name_
set theTarget to _XML_element_target_
...

只需从纯文本

创建一个新的 XML data 实例
set xmlText to "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
  <win>
  <name>Documents</name>
  <target>SSD:Documents:</target>
  <listview>1</listview>
  <sidebar>0</sidebar>
  <bounds>1200, 630, 1825, 1080</bounds>
</win>"

tell application "System Events"
    set xmlData to make new XML data with properties {text:xmlText}
    tell XML element "win" of xmlData
        set theName to value of XML element "name"
        set theTarget to value of XML element "target"
    end tell
end tell