LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Clarkey
- Posts: 109
- Joined: Fri Jun 11, 2010 11:10 am
Post
by Clarkey » Sun Jun 20, 2010 9:21 pm
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..
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sun Jun 20, 2010 10:13 pm
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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
-
Clarkey
- Posts: 109
- Joined: Fri Jun 11, 2010 11:10 am
Post
by Clarkey » Sun Jun 20, 2010 11:03 pm
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..