XML noob questions
kray at sonsothunder.com
Wed Oct 11 09:08:34 EDT 2006
On 10/11/06 7:09 AM, "Malte Brill" <revolution at derbrill.de> wrote:
> Hi all,
> I´m playing a bit with XML in rev at the moment. It seems I don´t get
> it from the docs. Any tuts on how to do useful things with Revs XML lib?
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> What I want to do now is to display in a field:
> Title: Default
> image ID 55514: /skin/top.jpg
> image ID 55515: /skin/pattern.jpg
> field myField: 45,78,90
> Any hints and codeSnippets much appreciated.
OK, here's the basics you'll need:
1) First you need to take the XML data and convert it to a "tree" structure
that the revXML DLL can parse. Here's an example (assuming this xml data
above is in a variable called "tData"):
put revCreateXMLTree(tData,true,true,false) into tTree
"tTree" in this case is an XML "tree" identifier - a way you can address
individual nodes in an XML tree structure. The parameters other than the
first one control whether to allow parsing of badly formatted XML, whether
you want to really create a tree or just parse the XML to check for errors,
and whether or not you want to get messages as its parsing the tree.
2) Once you have the tree parsed, you can then address individual nodes
using "node paths", which are /-delimited according to the parent/child
relationship of the nodes, and starting with "/" as the root of the tree.
You use revXMLNodeContents to get at the data between open/close tags. So
will get you the string "Default".
3) If you want the names of particular children of a node, you need to use
revXMLChildNames, which will return the names of the children of a node. So
would give you a return-delimited list of children of the <skin> node:
4) If children have the same name (like "image", above), you reference the
node by putting the index number of the node in square brackets after the
name of the node. So to get the children of the first image node, you'd do:
and for the second:
That should hopefully get you started...
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com
P.S. If you need an all-Transcript solution for XML parsing, or are working
with the XML from RSS feeds (among other things), then you might want to
check out my XML Library:
More information about the use-livecode