Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Applescript读取XML中的特定值_Xml_Xml Parsing_Applescript - Fatal编程技术网

Applescript读取XML中的特定值

Applescript读取XML中的特定值,xml,xml-parsing,applescript,Xml,Xml Parsing,Applescript,我正在尝试使用AppleScript读取XML <?xml version="1.0" encoding="UTF-8"?> <xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/"> <annots> <square color="#FF0000" creationdate="D:20130828114843+05'30'" date="D:20

我正在尝试使用AppleScript读取XML

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xml:space="preserve" xmlns="http://ns.adobe.com/xfdf/">
<annots>
<square            color="#FF0000" creationdate="D:20130828114843+05'30'"            date="D:20130828114901+05'30'" flags="print"            name="Xi6cOkAWgWHcAhpfBkR5A7" page="0"            rect="347.7599999991828,1041.8400000004283,453.5999999989341,1056.9600000003927"            subject="Rectangle"                title="1 im, awltest7 (AWLTEST7.IM)">
<contents-richtext>
<body>
<p>Text Not Clear</p>
</body>
</contents-richtext>
<popup                open="yes" page="0"            rect="453.5999999989341,944.4600000003926,573.5999999989341,1056.9600000003927"/>
</square>
<square            color="#FF0000" creationdate="D:20130828114910+05'30'"            date="D:20130828114919+05'30'" flags="print"            name="ptmmBKtfoDEbVzirMgZLnY" page="0"            rect="511.1999999987987,1092.960000000308,550.7999999987057,1123.9200000002352"            subject="Rectangle"                title="2 im, awltest7 (AWLTEST7.IM)">
<contents-richtext>
<body>
<p>Incorrect dimension</p>
</body>
</contents-richtext>
<popup                open="yes" page="0"            rect="550.7999999987057,1011.4200000002352,670.7999999987056,1123.9200000002352"/>
</square>
<square            color="#FF0000" creationdate="D:20130828114956+05'30'"            date="D:20130828115004+05'30'" flags="print"            name="8LaAl2Upx4LEaQptQKXoZx" page="0"            rect="355.67999999916424,731.5200000011573,431.99999999898483,750.2400000011135"            subject="Rectangle"                title="3 im, awltest7 (AWLTEST7.IM)">
<contents-richtext>
<body>
<p>Incorrect Text</p>
</body>
</contents-richtext>
<popup                open="yes" page="0" rect="431.99999999898483,637.7400000011133,551.9999999989849,750.2400000011135"/>
</square>
</annots>
</xfdf>
通过使用脚本,我成功地获得了''''值。如何获取值。请给出建议。

下面的脚本可以工作

tell application "System Events"
        set theXMLFile to XML file theXMLFile
        set squares to XML elements of XML element "annots" of XML element "xfdf" of theXMLFile whose name is "square"
        set p to {}
        set attrs to {}
        repeat with i from 1 to (count squares)
            set end of p to value of XML element "p" of XML element "body" of XML element "contents-richtext" of item i of squares
            set end of attrs to value of XML attributes of item i of squares
        end repeat
    end tell
tell application "System Events"
        set theXMLFile to XML file theXMLFile
        set squares to XML elements of XML element "annots" of XML element "xfdf" of theXMLFile whose name is "square"
        set p to {}
        set attrs to {}
        repeat with i from 1 to (count squares)
            set end of p to value of XML element "p" of XML element "body" of XML element "contents-richtext" of item i of squares
            set end of attrs to value of XML attributes of item i of squares
        end repeat
    end tell