1

I have an Applescript that receive an XML string formatted as parameter, and I would like to read/parse data. Received string looks like:

<?xml version="1.0" encoding="utf-8" ?>
  <win>
  <name>Documents</name>
  <target>SSD:Documents:</target>
  <listview>1</listview>
  <sidebar>0</sidebar>
  <bounds>1200, 630, 1825, 1080</bounds>
</win>

I saw examples with XML files but I can't figure how to populate a record based upon received string. Final record could be like this:

set myRecord to {name:_XML_element_name_, tg:_XML_element_target_, listview: ...}

Or I could use at least some variables:

set theName to _XML_element_name_
set theTarget to _XML_element_target_
...

1 Answer 1

2

Just make a new XML data instance from the plain text

set xmlText to "<?xml version=\"1.0\" encoding=\"utf-8\" ?>
  <win>
  <name>Documents</name>
  <target>SSD:Documents:</target>
  <listview>1</listview>
  <sidebar>0</sidebar>
  <bounds>1200, 630, 1825, 1080</bounds>
</win>"

tell application "System Events"
    set xmlData to make new XML data with properties {text:xmlText}
    tell XML element "win" of xmlData
        set theName to value of XML element "name"
        set theTarget to value of XML element "target"
    end tell
end tell
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.