Reading multiple identical nodes in an XML file

Dave Cragg dave.cragg at
Mon Oct 17 04:52:27 EDT 2011

On 17 Oct 2011, at 05:45, Sivakatirswami wrote:

> I am an XML newbie:
> if you want to extract data from a series of  identical nodes in a XML file, how do you set up the repeat function?

Here's one way. I'm sure there are others. (It returns a list of names and ages)


function namesAndAges xml
   put revCreateXMLTree(xml,true,true,false) into xmlID
   if xmlID is not a number then
      returm  xmlID -- error string
   end if
   put revXMLChildNames(xmlID,"/orphanage",comma,"small-child",true) into tChildren
   put empty into tRes	
   repeat for each item tChild in tChildren
      put "/orphanage/" & tChild  & "/name" into tNameNode
      put "/orphanage/" & tChild  & "/age" into tAgeNode
      put revXMLNodeContents(xmlID, tNameNode) into tName
      put revXMLNodeContents(xmlID, tAgeNode) into tAge
      put tName & ", " & tAge & cr after tRes
   end repeat

   return tRes
end namesAndAges

More information about the Use-livecode mailing list