You are directly asking the xfdf
element for p
, but xfdf
is not its parent. You need to dig down into the hierarchy to reach it.
set theXMLFile to ((choose file) as string)
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 XML element "popup" of item i of squares
end repeat
end tell
p --> {"Text Not Clear", "Incorrect dimension", "Incorrect Text"}
attrs --> {{"yes", "0", "453.5999999989341,944.4600000003926,573.5999999989341,1056.9600000003927"}, {"yes", "0", "550.7999999987057,1011.4200000002352,670.7999999987056,1123.9200000002352"}, {"yes", "0", "431.99999999898483,637.7400000011133,551.9999999989849,750.2400000011135"}}
Another option is to use the XML Tools Scripting Addition from Late Night Software.