I agree with Carl that XML is too much verbose compared to Rebol's Block but there is no equivalent of XML DOM library for Rebol's Block or am I mistaken ?
How can I iterate through a hierarchy of bloc开发者_JS百科k ?
Rebol's runtime abstraction of block! is not adequate for getting coverage of the DOM. One technical barrier is that you can't get the single unique "parent" of a block, as it may be aliased at several locations. So for instance:
>> foo: [div id: "foo"] == [div id: "foo"] >> bar: [div id: "bar"] == [div id: "bar"] >> paragraph: [p ["Hello"]] == [p ["Hello"]] >> append foo append/only [contents:] paragraph == [div id: "foo" contents: [p ["Hello"]]] >> append bar append/only [contents:] paragraph == [div id: "bar" contents: [p ["Hello"]]] >> append second paragraph "World" == ["Hello" "World"] >> foo/contents == [p ["Hello" "World"]] >> bar/contents == [p ["Hello" "World"]]
There's no way to write a function that can meaningfully answer questions like "get-parent bar/contents". Although you've got something which has been parsed and brought into a structure you can manipulate, it isn't a structure with particular designs matching the DOM.
To climb around it freely as a tree you'd have to build a bunch of objects connected with references. That's pretty much what every other language does, so no free lunch to be had here. On the plus side, part of the parsing is taken care of for you and there's quite a bit of manipulation you can do without a DOM library. It's a way better place to start than text!
On the downside, it can seem so freeform that you wonder what use cases it was optimized for. The answer is that it specifically wasn't optimized for anything, other than dialecting Rebol. :) Circular reasoning, but it has given rise to the properties that make the language interesting to study and which makes it sort of "timeless".
You might find aspects of the extended tag proposal and the discussion it provoked to be illuminating.
Yes Rebol can be used for these purposes. It can mimic any language by way of DSL's. Try %Rebol-DOM.r view with Mdlparser.
精彩评论