XML Handling

Ken Ray kray at sonsothunder.com
Sat Jun 14 15:18:36 EDT 2008


> What I'm not clear about is how I use Rev's XML functions to read in such a
> file, and populate my program's variables with the various values. It seems as
> though I would need to still write lots of nested loops, which suggests I'm
> missing a trick. Can anyone point me at some demonstration material that would
> help me generate an XML parser.

Actually, Rev's XML external handles this pretty easily; the basic approach
is to (a) hand an XML "document" off to the revXML external which will then
parse it and hand back a reference number to use to indicate that document
in memory, and then (b) start using XML-specific functions in Rev to access
the data.

For example, suppose your XML was in a file and you have already previously
read it into a variable called "myXMLData". Here's what you would do:

  -- Parse data into an XML tree in memory, with the ID of tTreeID
  put revCreateXMLTree(myXMLData,true,true,false) into tTreeID

  -- For clarity, I'm putting the "path" to the first header node into a
  -- variable
  put "/PEPMAP/HEADERS/HEADER[1]" into tHeaderNode

  -- Here's how to get the "value" attribute from the first HEADER
  put revXMLAttribute(tTreeID, tHeaderNode,"value") into tMyAttribData

  -- Here's how to get the contents of a node
  --   Note: Since I don't see any node contents in your XML, so let's
  -- assume the first header actually looked like this in your XML:
  --  <HEADER name="Head">QconCAT_LS1</HEADER>
  --
  put revXMLNodeContents(tTreeID, tHeaderNode) into tMyNodeData

Take a look in the Revolution Dictionary for anything with XML in it (you
can skip the ones that also have "RPC" in it for now).

Hope this helps get you started,

Ken Ray
Sons of Thunder Software, Inc.
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/





More information about the use-livecode mailing list