Subject: Re: TclXML/TclDOM - DN [1]
Steve Ball <Steve.Ball@zveno.com> - 20 Dec 1999 - comp.lang.tcl
Stanley Seat wrote:
>
> Could someone post a short sample of TclDOM code that shows how to process
> nodes of a XML document tree? Hopefully a few code examples will be a good
> tutorial.
My article in the October Web Techniques mag has a TclDOM example.
It shows how to construct XML-RPC queries using TclDOM. Here's an
update, this time creating a SOAP (v0.9) query. I'll intersperse my
comments in the code. This is a simple example which creates a document
from scratch. Perhaps someone else will post an example of reading an
existing document. SOAP also requires reading an existing document
(the response to the RPC), so there is an example in the package.
set rpc [dom::DOMImplementation create]
set cleanup [list dom::DOMImplementation destroy $rpc]
This starts the ball rolling by creating a DOM tree. The 'cleanup'
script is eval'ed if there's an error.
set call [dom::document createElement $rpc SerializedStream]
dom::element setAttribute $call headers headers
dom::element setAttribute $call main main
dom::element setAttribute $call xmlns:SOAP http://w3.org/Schemas/SOAP/kw
The 'SerializedStream' element is the document element in a SOAP RPC.
The standard dictates the use of various attributes, in particular the
SOAP namespace must be declared.
set methodNode [dom::document createElement $call $method]
We then encode the method name to invoke as an element name.
Following this the RPC parameters are added to the document.
That's just a bunch of createElement calls, so I'll omit the
details (read the code if you're interested).
Finally when the document has finished being built we turn it into
XML text (aka serialize) and send it on its way.
if {[catch {eval ::http::geturl [list $uri] \
-headers [list MessageType Call] \
-query [list [dom::DOMImplementation serialize $rpc]] \
$httpOptions} request]} {
eval $cleanup
return -code error [list HTTP_ERROR "HTTP request failed due to \"$request\""]
}
I hope that's illuminating.
Cheers,
Steve Ball
--
Steve Ball | Swish XML Editor | Training & Seminars
Zveno Pty Ltd | Web Tcl Complete | XML XSL
http://www.zveno.com/ | TclXML TclDOM | Tcl, Web Development
Steve.Ball@zveno.com +-----------------------+---------------------
Ph. +61 2 6242 4099 | Mobile (0413) 594 462 | Fax +61 2 6242 4099
Last modified
2000-01-04
2000-01-04
(195.108.246.50)
Note: you are looking at
the snapshot of an old wiki
- much of this information
is likely to be very outdated
