Hello,
I am trying to parse an XML file using Applescript see below -
<?xml version="1.0" encoding="utf-8"?> 83325 0 0 ALL All Items 261889 2015-01-02 12:06:50 83327 1 16711680 UNASSIGNED Unassigned Items 152883 2015-01-02 12:06:50 85667 2 0 EDIT DIELINE 0 2015-01-20 20:40:36I am trying to get the number in the 3rd element of the XML in this case 85667 this number can vary and also the position in the XML depending how many groups there are. The part which would alway’s be the same is DIELINE> i need to query for the number then pass this onto a shell script.
My code currently looks like this, i can get the number to show in results but unsure how to log or pass on.
set theXMLFile to ((choose file) as string)
tell application “System Events”
set xmlData to XML file theXMLFile
set found_elements to my getXMLElementsByName(“id”, contents of xmlData)
log (the value of (item 3 of found_elements) as text)
end tell
on getXMLElementsByName(search_name, search_xml_element)
set found to {}
using terms from application "System Events"
tell search_xml_element
set c to the count of XML elements
repeat with i from 1 to c
if (the name of XML element i is search_name) then
set found to found & {XML element i}
end if
if (the (count of XML elements of XML element i) > 0) then
set children_found to my getXMLElementsByName(search_name, XML element i)
if (the (count of children_found) > 0) then
set found to found & children_found
end if
end if
end repeat
end tell
end using terms from
return found
record getXMLElementsByName
end getXMLElementsByName
I have been working on this for 2 weeks now but no luck, i am fairly new to Applescript and i am trying to write some simple scripts to speed up some workflows for my DTP company.
Any help would be extremely appreciated.
Steve