I am trying to extract the temperature in “73.2”. I can get the data from but I can’t figure out how to get data from from . How do I get to to get the info I want?
set XMLfile to "Users:mcp:desktop:inwork:xmlfeed.xml"
tell application "System Events"
tell XML element 1 of contents of XML file XMLfile
set typeText to (value of (XML elements whose name is "currentConditions")) as string
set nameText to (value of (XML elements whose name is "readingDateTime")) as string
set nameText to (value of (XML elements whose name is "tempUnits")) as string
end tell
end tell
value of xml element "currentReading" of xml element "condition" of xml element "port" of xml element "ports" of xml element "currentCondiions"
If there are more ports and more conditions on each port you should fetch it by it’s attribute values
set XMLfile to "Users:mcp:desktop:inwork:xmlfeed.xml"
set currentReading to missing value
tell application "System Events"
set XMLRoot to contents of XML file XMLfile
repeat with thisPort in XML elements of (XML element "ports" of XML element "currentConditions" of XMLRoot)
if value of XML attribute "name" of thisPort = "Port 1" then
repeat with thisCondition in XML elements of thisPort
if value of XML attribute "type" of thisCondition = "temperature" then
set currentReading to value of XML element "currentReading" of thisCondition
exit repeat
end if
end repeat
exit repeat
end if
end repeat
end tell
return currentReading
Thanks for your reply but using your advise to “Just follow the path” I can’t get this to work
set XMLfile to "Users:mcppvb:desktop:inwork:xmlfeed.xml"
tell application "System Events"
value of (XML element "currentReading" of XML element "condition" of XML element "port" of XML element "ports" of XML element "currentCondiions") of XMLfile
end tell
set XMLfilePath to "Users:mcppvb:desktop:inwork:xmlfeed.xml"
tell application "System Events"
set XMLfile to XML file XMLfilePath
value of (XML element "currentReading" of XML element "condition" of XML element "port" of XML element "ports" of XML element "currentCondiions") of contents of XMLfile
end tell
Note: the root element of a XML file is always the property contents, take a closer look at DJ’s example