Note that you can implement tree support in J, if you
wish.  For example:

coclass 'htmltree'

create=:3 :0
 nms=:;:'parents nodes content classes'
 (nms)=:_1 0 1 0;(;:'html head title body');2#<4#a:
)

insert=:3 :0
 'p N C CL'=.(#>{.y){.!.a:&.>(#nms){.!.(<a:)y,&.><a:
 P=.p [EMAIL PROTECTED]:(32 ~: 3!:0 p)nodes
 (nms)=:(".&.>nms),&.>P;N;C;<CL
 i.i.2
)

emit=:3 :0
 r=.''
 for_ndx.,y do.
   if.#node=.ndx{::nodes do.
     r=.r,'<',node
     if.#cl=.ndx{::classes do.r=.r,' class="',cl,'"' end.
     r=.r,'>'
   end.
   r=.r,ndx{::content
   r=.r,emit I.parents=ndx
   if.#node do.r=.r,'</',node,'>',LF end.
 end.
 r
)


You can, of course, extend this class (or modify the code I
threw together), if you like.

Here's an example of how it might be used:

  page=:''conew 'htmltree'
  insert__page (<'body');a:;<<'Hi there'
  insert__page (<'body');(<'div');(<'more text');<<'content'
  emit__page 0
<html><head><title></title>
</head>
<body>Hi there<div class="content">more text</div>
</body>
</html>

As written, insert expects a list of four lists:

0: parent node list (required)
1: node name list (empty for text nodes)
2: content node list (empty for no textual prefix for contents)
3: class name list (empty for no class)

I can think of half a dozen different ways I might prefer to pass
this information, and I'm sure you can think of something you
might prefer as well.

insert should also perhaps be named append, because it's
somewhat analogous to javascript's appendChild method on
DOM elements (along with an appropriate createElement or
createTextNode and maybe a setAttribute('class', ...)).

And, of course, this code provides close tags for every
element it manages.  If you don't want that you'd either
have to give it special knowledge of html quirks, or you'd
have to represent such tags as raw html text.

Anyways, my point isn't that this code is all that great, or all
that awful -- my point is that you can easily provide your own
tree structured mechanisms, if that suits your tastes.

FYI,

--
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to