1

I searched here and Google and came up with nothing, so I am hoping that someone here can help me understand how to parse "href=" from the XML Header in the following example.

<?xml version="1.0" encoding="UTF-8"?>
<foo version="2" href="/event/189" product="Server">
    <name>The Name</name>
</foo>

Here is what I do know. To parse the element "name" in the xml file, I can do the following:

set source_xml to choose file "Select your xml source"
set posix_source_xml to POSIX path of source_xml

tell application "System Events"
    set xml_file to XML file posix_source_xml
    tell xml_file
        tell XML element "foo"
            set name_value to value of XML element "name"
        end tell
    end tell
end tell

But how do I get the value for "href=" in the "foo" header? I tried this with no success:

set source_xml to choose file "Select your xml source"
set posix_source_xml to POSIX path of source_xml

tell application "System Events"
    set xml_file to XML file posix_source_xml
    tell xml_file
        set foo_value to value of XML element "foo"
    end tell
end tell

Even if that did work, I would imagine it would return - version="2" href="/event/189" product="Server" - and not just - /event/189.

Any assistance on this would be greatly appreciated!

1
  • hey @snwbrdr78 how did this go? Did you have any luck with my answer? Commented Aug 27, 2014 at 6:51

1 Answer 1

1

There is an XML attribute property.

To get href from your example:

set href_value to value of XML attribute "href" of XML element "foo"
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.