[REBOL] Re: Simple XML
From: joel:neely:fedex at: 9-Mar-2004 15:47
Hi, Terry,
No script needed. PARSE-XML does what you're asking (given that
you can use the block convention it creates -- see below).
T. Brownell wrote:
> Is there any available scripts that turn xml into rebol blocks? So that ...
>
>> xml-stuff: {<root>
{ <person>
{ <name>
{ <fname>
{ Bob
{ </fname
{ <lname>
{ Smith
{ </lname>
{ </name>
{ </person>
{ </root>}
== {<root>
<person>
<name>
<fname>
Bob
</fname
<lname>
Smith
</ln...
>> block-stuff: parse-xml xml-stuff
== [document none [["root" none ["^/ " ["person" none ["^/ "
["name" none ["^/ " ["fname" none ["^/ Bob^/
...
The convention is that each XML element is represented by a 3-item
block, containing:
1) the name of the element/tag as a STRING!
2) attributes (as a block of name/value pairs) or NONE if no attrs
3) contents (as a block of the content items -- strings for text
and blocks for child elements) or NONE if no contents *AT*ALL*
IgnorableWhiteSpace is not ignored, but appears as STRING! content.
The entire XML string is wrapped in a mythical element whose tag is
the WORD! DOCUMENT with no attributes. If you juat want the XML
content, just take FIRST THIRD of the result of PARSE-XML, as in
(the line breaks were added for email formatting, and should be
eliminated if you try to cut and paste):
>> x: {<top><middle place='between'>
<bottom>down</bottom></middle></top>}
== {<top><middle place='between'>
<bottom>down</bottom></middle></top>}
>> print mold first third parse-xml x
["top" none [["middle" ["place" "between"] [["bottom" none ["down"]]]]]]
>>
HTH!
-jn-
--
Single bit errors are corrected. Joel Neely
Double bit errors are detected. joel dot neely
Undetected errors are ignored. at fedex dot com