[REBOL] Re: What's the 'none' for in the parse-xml result?
From: joel:neely:fedex at: 11-Jul-2001 2:20
Hi, Gavin,
Gavin F. McKenzie
wrote:
...
> ['document none none]
>
...
> parse-xml "<foo>bar</foo>"
>
> I get the result:
>
> [document none [["foo" none ["bar"]]]]
>
Just take your example a little further.
>>> parse-xml {<foo top="up" size="big">Hello!</foo>}
== [document none [["foo" ["top" "up" "size" "big"] ["Hello!"]]]]
The block REBOL produces for an XML element contains the
element name, attribute list, and content, in that order.
The following aliases are handy...
>> alias 'third "content-of"
== content-of
>> alias 'second "attributes-of"
== attributes-of
An element that has no attributes has NONE for its second
part, just as an element that has no content has NONE for
its third part. Each item in the content block (if there
is one) will either be a string or a block (of similar
structure) for a subordinate element.
>> parse-xml {<foo><bletch /></foo>}
== [document none [["foo" none [["bletch" none none]]]]]
When attributes are present, they are presented in a block
of name/value pairs suitable for searching with SELECT/SKIP
>> parse-xml {<socks color="navy" fiber="cotton" />}
== [document none [["socks" ["color" "navy" "fiber" "cotton"]
none]]]
>> select/skip attributes-of first content-of x "color" 2
== ["navy"]
> I'm writing up an extended version of parse-xml that
> addresses many of the non-compliance issues with the
> built-in parse-xml (such as lack of CDATA section support,
> namespaces etc.), and I'm betting that the first none value
> is intended for future use to hold the document's prolog
> (such as the internal DTD subset).
>
Based on looking at the code for XML-LANGUAGE, my conclusion
was that the block for the top-level document was simply
another block that followed the above structure (to avoid
fencepost issues).
I wrote extensions to handle comments and CDATA a while back,
and had thought about doing an article on XML in REBOL. (Are
you interested in collaborating?) But I'm not sure what you
have in mind for namespaces. Were you thinking of actually
writing a validating parser?
-jn-
---------------------------------------------------------------
There are two types of science: physics and stamp collecting!
-- Sir Arthur Eddington
joel-dot-neely-at-fedex-dot-com