XML Tutorial
Alex Rice
alex at mindlube.com
Tue Jan 13 02:00:28 EST 2004
On Jan 12, 2004, at 8:41 AM, Thomas J McGrath III wrote:
> Does anyone have a stack that shows how XML's work in Rev for
> 'beginners'?
I think core concepts with revXML are:
A xml tree ID (doc ID) is just an integer. Save it in a variable, for
use with the other revxml functions.
A xml node ID is a string - a path "/root/x/y/child" showing the parent
and child relationship to the node.
A xml node ID can have array notation with square brackets e.g.
"/root/x/y/child[3]" to indicate the 3rd node.
--
Here is some sample code. This is a DOM usage (as opposed to SAX):
put revCreateXMLTreeFromFile("macbeth.xml",true, true, false) into
tDocID
-- the speaker of speech 7, scene 3, act 5.
put revXMLChildContents(tDocID,
"/play/act[5]/scene[3]/speech[7]/speaker")
--returns
MACBETH
-- the stagedir of speech 7, scene 3, act 5.
put revXMLText(tDocID, "/play/act[5]/scene[3]/speech[7]/stagedir")
-- returns
<STAGEDIR>Exit Servant</STAGEDIR>
-- the 8th line of speech 7, scene 3, act 5.
put revXMLText(tDocID, "/play/act[5]/scene[3]/speech[7]/line[8]")
-- returns
<LINE>As honour, love, obedience, troops of friends,</LINE>
--or you can use a more general node to get more text back
put revXMLText(tDocID, "/play/act[5]/scene[3]/speech[7]")
-- returns
<SPEECH><SPEAKER>MACBETH</SPEAKER>
<LINE>Take thy face hence.</LINE>
...
</SPEECH>
-- Use this function to pretty-print a selected chunk of xml.
put revXMLChildContents(tDocID, "/play/act[5]/scene[3]/speech[7]", ":"
&tab & tab, linefeed, false, -1)
-- returns
SPEAKER: MACBETH
LINE: Take thy face hence.
STAGEDIR: Exit Servant
LINE: Seyton!--I am sick at heart,
LINE: When I behold--Seyton, I say!--This push
LINE: Will cheer me ever, or disseat me now.
LINE: I have lived long enough: my way of life
LINE: Is fall'n into the sear, the yellow leaf;
LINE: And that which should accompany old age,
LINE: As honour, love, obedience, troops of friends,
LINE: I must not look to have; but, in their stead,
LINE: Curses, not loud but deep, mouth-honour, breath,
LINE: Which the poor heart would fain deny, and dare not. Seyton!
Alex Rice <alex at mindlube.com> | Mindlube Software |
<http://mindlube.com>
what a waste of thumbs that are opposable
to make machines that are disposable -Ani DiFranco
More information about the use-livecode
mailing list