So I recently found out about XML-Parsing in Applescript. I wanted to parse an XML file that had a structure like this:
<example>
<sample value="hello world"/>
</example>
So I tried something like this:
tell application "System Events"
tell XML file "/path/to/the/file.xml"
tell XML element "example"
return XML attribute "value" of XML element "sample"
end tell
end tell
end tell
However, the error says:
System Events got an error: Can’t get XML element "example" of XML file "~/Desktop/xml.xml" number -1728.
According to MacErrors.h number -1728 means errAENoSuchObject, so no such object was found. What am I doing wrong?

get name of every XML element of XML file "~/Desktop/xml.xml"to see.NSXMLclasses via the AppleScript-ObjC bridge. The ObjC API’s a bit more complex, but is faster than using System Events and supports more powerful XPath queries.getcommand in atell app "System Events"block, e.g.tell app "System Events" to get name of every XML element of XML file "~/Desktop/xml.xml". Referencing files is a mess in AppleScript, but in this case you’re dealing with the System Events app so just give it a valid POSIX path string to your XML file. If can’t find the file it’ll tell you, e.g. “System Events got an error: Can’t get XML file "~/tesst.xml".” number -1728. Your error message indicates it found the file okay, but can’t find the root<example>…</example>element within it.number -1703, which means some data is in the wrong type.