I am trying to parse data from a networked media player.
I can access the data on the player via the following endpoint:
http://192.168.10.2:8008/GetUserVars
This returns the following data:-
<?xml version="1.0" encoding="UTF-8"?>
<BrightSignUserVariables>
<BrightSignVar name="CurrentLetter">W</BrightSignVar>
<BrightSignVar name="CurrentUserName">&Q&W&Q&W&Q&W&Q&W</BrightSignVar>
</BrightSignUserVariables>
From this I need to use AppleScript to get the values from the BrightSignVar XML element node whose name attribute is CurrentLetter and CurrentUserName.
Essentially, I want to obtain these two text nodes:
W&Q&W&Q&W&Q&W&Q&W
I tried the following example but got errors, any ideas?
set theXMLFile to ((http://192.168.10.2:8008/GetUserVars) as string)
tell application "System Events"
set CurrUser to (value of XML element "CurrentUserName")
set CurrLetter to (value of XML element "CurrentLetter")
end tell
Edit:
I have also tried the following:
set theXMLFile to (do shell script (("curl -X GET 'http://192.168.10.5:8008/GetUserVars'")))
tell application "System Events"
set CurrUser to XML elements of XML element "BrightSignVar" of XML element "BrightSignUserVariables" of theXMLFile whose name is "CurrentUserName"
end tell
This returns the response as above however I get an error when trying to set CurrUser as variable:
can't make "BrightSignUserVariables" into type integer (-1700)
tell XML data of XML file theFilePath … end tellblock. 2. System Events only works on local files so usecurl(via Standard Additions’do shell scriptcommand) to download the XML data to file first.