From: Steve B. <Ste...@zv...> - 2004-09-14 20:59:57
|
On 15/09/2004, at 12:37 AM, Detlef Groth wrote: > I like the itcl/tk- and Tdom-like calling conventions for tdom: TclDOM version 3.0 has introduced that style of API, but not uniformly throughout the package (yet). At the time that I was implementing this feature I had an issue with overloading the document/node commands with methods for multiple node classes. For example, an element node is both a Node and an Element class object, so should have the methods for both the ::dom::node and ::dom::element commands. However, a TextNode or a Document node will have a different set a methods. > (tclkit) 82 % set doc [dom::DOMImplementation create] > ::dom::tcl::document7::Document > (tclkit) 83 % set top [dom::document createElement $doc html] > ::dom::tcl::document7::node2 > (tclkit) 84 % set title [$doc createElement title] > ::dom::tcl::document7::node6 > (tclkit) 85 % $top appendChild $title > ::dom::tcl::document7::node6 > (tclkit) 86 % set body [$doc createElement body] > ::dom::tcl::document7::node13 > (tclkit) 87 % $top appendChild $body > ::dom::tcl::document7::node13 > (tclkit) 88 % $body setAttribute bgcolor black > unknown method "setAttribute" > > This does not work, however this: > > (tclkit) 90 % dom::element setAttribute $body bgcolor black > black Yes, that exactly the issue raised above. "setAttribute" is a method of the ::dom::element command. You'd like to be able to do: $body setAttribute bgcolor black What happens if you do: $doc setAttribute bgcolor black The latter should probably throw an exception. Making the former work would mean either defining the node command as a separate function and implementing every method from every node class command (for both Tcl and libxml2), or modifying the node command to call the class-specific function if the method is not defined (actually, the latter would be the best approach). > which is for me a little bit awkward, and I always forget to add the > nodename after the (get|set)Attribute-command. I am used to javascript > where we say something like: > > var input = window.document.createElement("input"); > input.setAttribute("name", "inputvalue"); Having to remember to add the node token does make the API a bit awkward, I agree. > It should be not to difficult to write some simple wrapper classes > with Snit or something similar. But using snit may slow down the code. > Did > anyone have a better suggestion? Do it in the TclDOM package itself; please submit a feature request to SF. At the moment I'm flat-out with other (paid-for) projects so I won't be able to do anything about it in the short-term. However, maybe someone else will step up to the plate and give it a go. > As a side effect the same code might run with tdom also. Ah... that's a sore point. You go talk to the tDOM people about compatibility :-( Cheers, Steve Ball --- Steve Ball | XSLT Standard Library | Training & Seminars Zveno Pty Ltd | Web Tcl Complete | XML XSL Schemas http://www.zveno.com/ | TclXML TclDOM | Tcl, Web Development Ste...@zv... +---------------------------+--------------------- Ph. +61 2 6242 4099 | Mobile (0413) 594 462 | Fax +61 2 6242 4099 |