From: Lee T. <lee...@pl...> - 2001-05-08 19:53:40
|
Hi - I've been working with your tcldom package, and I'm impressed! The tcl xml parser seemed a little slow with large arrays (85 elements) so I've been looking into the C version (tcldompro.c). I've got it compiled as an AOLServer module, and it seemed to be working fine (we had a little trouble getting it to compile with namespaces, but we figured it out. I'll send you a patch if you want), but I do have a question: Does dom::DOMImplementation behave differently with the C version? Here's what I'm trying to do: with the tcl version: %set doc [dom::DOMImplementation create] ::dom::document1(node1) the C version: %set doc [dom::DOMImplementation create] node9 with the tcl version, I can then take $doc and run "dom::DOMImplementation serialize" on it to create the xml. But, with the C version, it says, "document has no document element" Also, with the TCL version, doing a "namespace eval ::dom { info vars }" gives me "document1" (the array in the above case) and "document1var1", etc. The C version does not. Thanks for *any* light you can shed on this. Lee Teague -- Lee Teague Placemark Investments lee...@pl... |
From: Joe E. <jen...@fl...> - 2001-05-08 20:34:53
|
Lee Teague <lee...@pl...> wrote: > I've got [dom::c] compiled as an AOLServer module, > and it seemed to be working fine (we had a little trouble getting it to compile > with namespaces, but we figured it out. I'll send you a patch if you want) Do you mean Tcl namespaces, XML namespaces, or C++ namespaces? Or something else? At any rate, yes, please send a patch and I'll get it integrated. What problems did you run into? > I do have a question: Does dom::DOMImplementation behave differently with the C > version? Probably. Any differences in documented functionality should be considered a bug though. (There are many differences in implementation details - like the representation of nodes - but those are inconsequential). > Here's what I'm trying to do: > with the tcl version: > %set doc [dom::DOMImplementation create] > ::dom::document1(node1) > > the C version: > %set doc [dom::DOMImplementation create] > node9 > > with the tcl version, I can then take $doc and run "dom::DOMImplementation > serialize" on it to create the xml. But, with the C version, it says, "document > has no document element" That's odd; the Tcl version gives me the same error as the C version ("document has no document element"). What version of dom::tcl do you have installed? You need to create a root element node before serializing the document; things should work properly then. I think that raising an error is the correct behaviour in this case. The documentation for [dom::DOMImplementation serialize] says that "the text is guaranteed to be a well-formed XML document", and there's no way to meet that guarantee unless there's exactly one document element. > Also, with the TCL version, doing a "namespace eval ::dom { info vars }" gives > me "document1" (the array in the above case) and "document1var1", etc. The C > version does not. That's one of the inconsequential implementation details mentioned above :-) The C version stores the tree in an internal data structure, where the Tcl version uses Tcl variables in the ::dom namespace. --Joe English jen...@fl... |
From: Lee T. <lee...@pl...> - 2001-05-08 21:21:13
|
----- In reply to "Re: [Tclxml-users] tcldompro.c" from Joe English <jen...@fl...> ----- > > Lee Teague <lee...@pl...> wrote: > > > Here's what I'm trying to do: > > with the tcl version: > > %set doc [dom::DOMImplementation create] > > ::dom::document1(node1) > > > > the C version: > > %set doc [dom::DOMImplementation create] > > node9 > > > > with the tcl version, I can then take $doc and run "dom::DOMImplementation > > serialize" on it to create the xml. But, with the C version, it says, "document > > has no document element" > > That's odd; the Tcl version gives me the same error as the C version > ("document has no document element"). What version of dom::tcl do you > have installed? > > You need to create a root element node before serializing the > document; things should work properly then. > So how do I create a "root element"? With the TCL version, all my code works fine, but with this C version, it complains about "no document element". I'll include a code snippet at the bottom of this msg to show you exactly what's happening. Again, the TCL version creates the XML just fine like this. Thanks for your help! --------- CODE THAT WORKS WITH THE TCL VERSION ------------------- set methodName "get_state" set doc [dom::DOMImplementation create] set env [dom::document createElement $doc "SOAP-ENV:Envelope"] dom::element setAttribute $env "xmlns:SOAP-ENV" "http://schemas.xmlsoap.org/soap/envelope/" dom::element setAttribute $env "xmlns:xsi" "http://www.w3.org/1999/XMLSchema-instance" dom::element setAttribute $env "xmlns:xsd" "http://www.w3.org/1999/XMLSchema" set bod [dom::document createElement $env "SOAP-ENV:Body"] set cmd [dom::document createElement $bod $methodName] dom::element setAttribute $cmd "SOAP-ENV:encodingStyle" "http://schemas.xmlsoap.org/soap/encoding/" set par [dom::document createElement $cmd state] dom::element setAttribute $par "xsi:type" "xsd:string" dom::document createTextNode $par Texas regsub {<!DOCTYPE[^>]*>\n} [dom::DOMImplementation serialize $doc] {} result dom::DOMImplementation destroy $doc return $result --------- CODE THAT WORKS WITH THE TCL VERSION ------------------ -------------- XML RESULT FROM TCL VERSION ---------------------- <?xml version='1.0'?> <SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <SOAP-ENV:Body> <get_state SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <state xsi:type="xsd:string"> Texas </state> </get_state> </SOAP-ENV:Body> </SOAP-ENV:Envelope> -------------- XML RESULT FROM TCL VERSION ---------------------- -- Lee Teague Placemark Investments lee...@pl... |
From: Daniel <da...@co...> - 2001-05-08 21:33:41
|
Hi, Since you are using soap, you may be interested in: http://www.zsplat.freeserve.co.uk/soap/doc/TclSOAP.html > > --------- CODE THAT WORKS WITH THE TCL VERSION ------------------- > > set methodName "get_state" > > set doc [dom::DOMImplementation create] > > set env [dom::document createElement $doc "SOAP-ENV:Envelope"] -- da...@co... "Fortuna audaces juvat" |
From: Lee T. <lee...@pl...> - 2001-05-08 21:55:08
|
I actually am using some of that package. It requires tclxml. What i'm trying to do is a little more specialized than what that package does, so I'm having to write some of the DOM stuff directly. ----- In reply to "Re: [Tclxml-users] tcldompro.c" from Daniel <da...@co...> ----- > Hi, > > Since you are using soap, you may be interested in: > http://www.zsplat.freeserve.co.uk/soap/doc/TclSOAP.html > > > > > --------- CODE THAT WORKS WITH THE TCL VERSION ------------------- > > > > set methodName "get_state" > > > > set doc [dom::DOMImplementation create] > > > > set env [dom::document createElement $doc "SOAP-ENV:Envelope"] > > -- > da...@co... "Fortuna audaces juvat" > > _______________________________________________ > Tclxml-users mailing list > Tcl...@li... > http://lists.sourceforge.net/lists/listinfo/tclxml-users > -- Lee Teague Placemark Investments 972.404.8100x31 | lee...@pl... |
From: Joe E. <jen...@fl...> - 2001-05-08 22:03:41
|
> > You need to create a root element node before serializing the > > document; things should work properly then. > > So how do I create a "root element"? Ah, now I see the problem: one of the main differences between dom::tcl and dom::c is that, in dom::tcl, dom::document createXXX $parent ... adds the new node as a child of $parent, whereas dom::c creates it as an unattached, parentless node. You have to add the new node "by hand", e.g.,: dom::node appendChild $parent [dom::document createXXX $parent ...] The dom::tcl behaviour is more intuitive and useful, but the dom::c behaviour matches the W3C DOM specification more closely. When I last asked Steve about this he indicated that it would be best to follow the W3C spec. Steve - is this still your take on things, or would it be better to change dom::c to match the documentation and dom::tcl? --Joe English jen...@fl... |
From: Steve B. <Ste...@zv...> - 2001-05-09 05:22:59
|
Joe English wrote: > > > > You need to create a root element node before serializing the > > > document; things should work properly then. > > > > So how do I create a "root element"? > > Ah, now I see the problem: one of the main differences between > dom::tcl and dom::c is that, in dom::tcl, > > dom::document createXXX $parent ... > > adds the new node as a child of $parent, whereas > dom::c creates it as an unattached, parentless node. > You have to add the new node "by hand", e.g.,: > > dom::node appendChild $parent [dom::document createXXX $parent ...] > > The dom::tcl behaviour is more intuitive and useful, > but the dom::c behaviour matches the W3C DOM specification > more closely. When I last asked Steve about this he > indicated that it would be best to follow the W3C spec. > > Steve - is this still your take on things, or would > it be better to change dom::c to match the documentation > and dom::tcl? After some time for reflection, I think we'll stick with the non-standard feature. If users want to, they can use TclDOM in such a manner that it is standard (ie. create node using factory method, then insert). My plan for TclDOM is to make a 'theta' release like I did for TclXML. That work will involve bringing the C and Tcl implementations into sync, as well as perhaps adding support for tDOM-style features, like more OO style node commands. Of course, we'll throw in DOM Level 2 and 3 support for good measure ;-) Now I just have to find the time... Cheers, Steve Ball -- Steve Ball | waX Me Lyrical XML Editor | Training & Seminars Zveno Pty Ltd | Web Tcl Complete | XML XSL 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 |
From: Joe E. <jen...@fl...> - 2001-05-09 01:09:10
|
I've just updated the dom::c package to make it compatible with dom::tcl and the TclDOM documentation: [dom::document createXXX $node1 ...] now creates the new node as a child of $node1. This is largely compatible with the old dom::c behavior -- typical usage is to insert nodes at the right point in the tree immediately after creating them, and scripts that do so will still work the same since the implementation automatically unlinks and reparents the new node. The test suite still passes, so I'm fairly confident that this change won't break anything. There's also a compile-time option (-DW3C_CONSTRUCTOR_BEHAVIOR) to get the old behaviour back. Lee -- can you get a fresh copy from Sourceforge CVS and see if that works now? --Joe English jen...@fl... |
From: Lee T. <lee...@pl...> - 2001-05-09 04:03:31
|
you, my friend, kick ass. thank you. ----- In reply to "Re: [Tclxml-users] tcldompro.c" from Joe English <jen...@fl...> ----- > > > I've just updated the dom::c package to make it compatible > with dom::tcl and the TclDOM documentation: > [dom::document createXXX $node1 ...] now creates the new node > as a child of $node1. > > This is largely compatible with the old dom::c behavior -- > typical usage is to insert nodes at the right point in the tree > immediately after creating them, and scripts that do so will > still work the same since the implementation automatically unlinks and > reparents the new node. The test suite still passes, so I'm > fairly confident that this change won't break anything. > > There's also a compile-time option (-DW3C_CONSTRUCTOR_BEHAVIOR) > to get the old behaviour back. > > Lee -- can you get a fresh copy from Sourceforge CVS and > see if that works now? > > > --Joe English > > jen...@fl... > -- Lee Teague Placemark Investments 972.404.8100x31 | lee...@pl... |
From: Lee T. <lee...@pl...> - 2001-05-08 22:44:23
|
here's the source: http://www.placemark.com/~lee/ns_tcldom.tar.gz just untar it into your aolserver source tree, or set NS_HOME in the Makefile to the location of your source tree. here's what we had to change: of course the Makefile to work with aolserver modules, etc. (didn't have to, but it made it so much nicer...) the following lines in tcldompro.c were added/replaced: --------------------------------------------- #include "ns.h" ... int Ns_ModuleInit(char *hServer, char *hModule) { /* AOLserver doesn't deal well with namespaces in C modules * so we need to reinitialize this module everytime a new * interp thread is created by AOLserver. */ Ns_TclRegisterAtCreate ( tcldominit, NULL); return (Ns_TclInitInterps(hServer, tcldominit, NULL)); } ///// in tcldominit: static int tcldominit( Tcl_Interp *interp, void *context ) .... //return Tcl_PkgProvide(interp, PACKAGE_NAME, VERSION); return NS_OK; --------------------------------------------- If you run through the code, you may notice a few other small differences, but the big one was "Ns_ModuleInit". The pain in the neck was figuring out that we had to use "Ns_TclRegisterAtCreate" to make it reload the commands with every thread. This isn't loading the file, it's just calling "Tcl_CreateObjCommand" a few times with every thread. Note: this isn't done, I'm writing this mailing list because we're having problems with it. Hopefully this will be of some use to someone, or maybe it'll help someone help us with this problem. BIG thanks to Jeremy Collins for making this work. - Lee Teague ----- In reply to "Re: [Tclxml-users] tcldompro.c" from Dave Bauer <da...@ki...> ----- > Wow, > > I am very interested in an AOLserver module with TclDOM. Do you mind sharing > the code or how you accomplished this feat? > > Right now we are using ns_xml with is a AOLserver module using libxml2 for > OpenACS, but the interface is very basic. TclDOM has a really nice interface > on the other hand, but the TCL version is slow. > Thanks > > Dave Bauer > da...@th... > > ----- Original Message ----- > From: "Lee Teague" <lee...@pl...> > To: <tcl...@li...> > Sent: Tuesday, May 08, 2001 3:50 PM > Subject: [Tclxml-users] tcldompro.c > > > > Hi - > > > > I've been working with your tcldom package, and I'm impressed! The tcl > xml > > parser seemed a little slow with large arrays (85 elements) so I've been > looking > > into the C version (tcldompro.c). I've got it compiled as an AOLServer > module, > > and it seemed to be working fine (we had a little trouble getting it to > compile > > with namespaces, but we figured it out. I'll send you a patch if you > want), but > > I do have a question: Does dom::DOMImplementation behave differently with > the C > > version? Here's what I'm trying to do: > > > > > > with the tcl version: > > > > %set doc [dom::DOMImplementation create] > > ::dom::document1(node1) > > > > the C version: > > > > %set doc [dom::DOMImplementation create] > > node9 > > > > > > with the tcl version, I can then take $doc and run "dom::DOMImplementation > > serialize" on it to create the xml. But, with the C version, it says, > "document > > has no document element" > > > > Also, with the TCL version, doing a "namespace eval ::dom { info vars }" > gives > > me "document1" (the array in the above case) and "document1var1", etc. > The C > > version does not. > > > > Thanks for *any* light you can shed on this. > > > > > > > > Lee Teague > > > > > > -- > > Lee Teague > > Placemark Investments > > lee...@pl... > > > > _______________________________________________ > > Tclxml-users mailing list > > Tcl...@li... > > http://lists.sourceforge.net/lists/listinfo/tclxml-users > > > > -- Lee Teague Placemark Investments 972.404.8100x31 | lee...@pl... |