The XML module in Phobos
Michel Fortin
michel.fortin at michelf.com
Sat Aug 1 06:18:41 PDT 2009
On 2009-08-01 00:04:01 -0400, Benji Smith <dlanguage at benjismith.net> said:
> But XML documents aren't really lists. They're trees.
>
> Do ranges provide an abstraction for working with trees (other than the
> obvious flattening algorithms, like breadth-first or depth-first
> traversal)?
Well, it depends at what level you look. An XML document you read is
first a list of bytes, then a list of Unicode characters, then you
convert those characters to a list of tokens -- the Tango pull-parser
sees each tag and each attribute as a token, SAX define each tag
(including attributes) as a token and calls it an event -- and from
that list of token you can construct a tree.
The tree isn't a list though, and a range is a unidimentional list of
something. You need another interface to work with the tree.
But then, from the tree, create a list in one way or another
(flattening, or performing an XPath query for instance) and then you
can have a range representing the list of subtrees for the query if you
want. That's pretty good since with a range you can lazily iterate over
the results.
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list