本文介绍了如何从Applescript中的字符串(不是文件)创建XML?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Applescript,它接收格式化为参数的XML字符串,并且我想读取/解析数据.收到的字符串如下:
I have an Applescript that receive an XML string formatted as parameter, and I would like to read/parse data. Received string looks like:
<?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文件的示例,但是我不知道如何根据接收到的字符串填充记录.最终记录可能是这样的:
I saw examples with XML files but I can't figure how to populate a record based upon received string. Final record could be like this:
set myRecord to {name:_XML_element_name_, tg:_XML_element_target_, listview: ...}
或者我可以至少使用一些变量:
Or I could use at least some variables:
set theName to _XML_element_name_
set theTarget to _XML_element_target_
...
推荐答案
只需使用纯文本
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
这篇关于如何从Applescript中的字符串(不是文件)创建XML?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!