I want to assign the value after Type= to a variable in applescript.
I have used http://www.latenightsw.com/freeware/XMLTools2/ on other XMLs with success.
but I cant figure out how I might get to the value after Type=
Its probably staring me in the face but I just cant see it
you can parse XML files without any third party additions
set xmlPath to "MacHD:path:to:XMLFile.xml"
tell application "System Events"
set xmlFile to XML file xmlPath
tell contents of xmlFile
set eventXMLElement to XML element 1 of XML element "Events" of XML element "ChangeList" of XML element "FilmScribeFile"
set typeAttribute to value of XML attribute "Type" of eventXMLElement
end tell
end tell
I needed to specify |Type| not name in the routine
on list_position(this_item, this_list)
repeat with i from 1 to the count of this_list
if item i of this_list is this_item then return i
end repeat
return 0
end list_position
on getAnElement(theXML, theElementName)
-- find and return a particular element (this presumes there is only one instance of the element)
repeat with anElement in XML contents of theXML
if class of anElement is XML element and ¬
XML tag of anElement is theElementName then
return contents of anElement
end if
end repeat
return missing value
end getAnElement
on getElements(theXML, theElementName)
-- find and return all instatnces of a particular element
local theResult
set theResult to {}
repeat with anElement in XML contents of theXML
if class of anElement is XML element and ¬
XML tag of anElement is theElementName then
set end of theResult to contents of anElement
end if
end repeat
return theResult as list
end getElements
on getElementFromPath(theXML, theElementPath)
if theElementPath is {} then
return theXML
else
local foundElement
set foundElement to getAnElement(theXML, item 1 of theElementPath)
if foundElement is not missing value and ¬
class of foundElement is XML element then
return getElementFromPath(foundElement, rest of theElementPath)
else
return missing value
end if
end if
end getElementFromPath
on getNamedElement(theXML, theElementName, theName)
-- find and return the first element with a particular name attribute
if class of theXML is XML element or class of theXML is XML document then
repeat with anElement in XML contents of theXML
try
if class of anElement is XML element and ¬
XML tag of anElement is theElementName and ¬
|Type| of XML attributes of anElement is theName then
return contents of anElement
end if
on error number -1728
-- ignore this error
end try
end repeat
else if class of theXML is list then
repeat with anElement in theXML
try
if class of anElement is XML element and ¬
XML tag of anElement is theElementName and ¬
|Type| of XML attributes of anElement is theName then
return contents of anElement
end if
on error number -1728
-- ignore this error
end try
end repeat
end if
return missing value
end getNamedElement
set changelistxml to {}
set changelistxml to (choose file with prompt "select MASTER ss template") as alias
set eventsxml to getAnElement((getAnElement(parse XML changelistxml, "ChangeList")), "Events")
set xmlevent to getAnElement(eventsxml, "Event")
if XML contents of (getNamedElement(eventsxml, "Event", "Delete")) is not equal to missing value then
display dialog "found attribute"
end if