ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> tclxml-users
tclxml-users
Re: [Tclxml-users] itcl/tk-like calling syntax for TclDom
by Steve Ball other posts by this author
Sep 14 2004 2:10PM messages near this date
[Tclxml-users] itcl/tk-like calling syntax for TclDom | Re: re[4]: [Tclxml-users] Dom node problems with tclsoap 1.6.7, tcldom 2.6 (libxml2)
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
Steve.Ball@[...].com  +---------------------------+---------------------
Ph. +61 2 6242 4099   |   Mobile (0413) 594 462   | Fax +61 2 6242 4099



-------------------------------------------------------
This SF.Net email is sponsored by: thawte's Crypto Challenge Vl
Crack the code and win a Sony DCRHC40 MiniDV Digital Handycam
Camcorder. More prizes in the weekly Lunch Hour Challenge.
Sign up NOW http://ad.doubleclick.net/clk;10740251;10262165;m
_______________________________________________
Tclxml-users mailing list
Tclxml-users@[...].net
https://lists.sourceforge.net/lists/listinfo/tclxml-users
Thread:
Detlef Groth
Steve Ball

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved