Page 1 of 1

XML list extraction advice sought

Posted: Sun Jun 20, 2010 9:21 pm
by Clarkey
Hi folks, I want to extract a list of the element "name" (i.e. Fred, Tom, Mary...) from the following XML file structure into a variable "tObjectNames", but being new to Revolution and its XML and text functions, I can't see an obvious way past the multiple instances of the "object" element. Any tips?

Code: Select all

<result>
    <object>
        <something>value</something>
        <name>Fred</name>
        <somethingElse>value</somethingElse>
    </object>
    <object>
        <something>value</something>
        <name>Tom</name>
        <somethingElse>value</somethingElse>
    <object>
    </object>
        <something>value</something>
        <name>Mary</name>
        <somethingElse>value</somethingElse>
    </object>
</results>
Thanks
Keith..

Re: XML list extraction advice sought

Posted: Sun Jun 20, 2010 10:13 pm
by Mark
Hi Keith,

I don't know what you want to do with the result, nor why you want to use XML, but if all you need is a list of the data in element "name" then the following script does what you need:

Code: Select all

on mouseUp
     put fld 1 into myList
     filter myList with "*<name>*</name>*"
     put replacetext(myList,"[<>]",",") into myList
     repeat for each line myLine in myList
          put item 3 of myLine & cr after myNewList
     end repeat
     put myNewList
end mouseUp
If you have a field 1 that contains the XML data then you will end up with a list in the message box.

Best,

Mark

Re: XML list extraction advice sought

Posted: Sun Jun 20, 2010 11:03 pm
by Clarkey
Hi Mark, Thanks for the response and the insights on the filter command - I hadn't discovered this yet but it looks to be just what I need.

I'm starting from an XML tree that is derived from a received web service SOAP message response. I had used a revXMLChildContents() function to generate a 'flattenned-out' list of the two levels of all relevant elements in the XML tree but couldn't find an XML 'query' mechanism to filter this list. The output list doesn't needs to be XML, so the text filter worked perfectly to remove all the non-essential list entries.

Thanks again!
Keith..