From: Steve B. <Ste...@zv...> - 2002-09-06 23:05:21
|
Derek Fountain wrote: > I'm creating a tree from scratch, and want to get a processing instruction in > at the top. I want, for example, this: > > <?xml version="1.0"> > <?xml-stylesheet type="text/xsl" href="test_view.xsl"?> > <!DOCTYPE test SYSTEM "test.dtd"> > <test /> > > How do I get the stylesheet PI in there? I have a bit of code like this: Ouch! It doesn't fit in with what TclDOM is trying to do, which is to manage the serialisation of the DOM tree on your behalf. I think we'll need to make the DocType an explicit node. This will allow other nodes to be inserted before and after. As a workaround, I'd switch off serialising the document prologue and do that in the script by prepending to the output of the serialised document. HTHs, Steve Ball > #!/bin/sh > # \ > exec tclsh8.3 "$0" "$@" > > package require xml > package require dom > > set doc [::dom::DOMImplementation create] > set testNode [::dom::document createElement $doc "test"] > > dom::document createProcessingInstruction \ > $doc "xml-stylesheet" {type="text/xsl" href="test_view.xsl"} > > puts [::dom::DOMImplementation serialize $doc] > > which produces: > > <?xml version='1.0'?> > <!DOCTYPE test> > <test/> > > i.e. no PI at all. If I change the target node for the PI from $doc to > $testNode I get: > > <?xml version='1.0'?> > <!DOCTYPE test> > <test><?xml-stylesheet type="text/xsl" href="test_view.xsl"?></test> > > i.e. PI now serialised, but in the wrong place. > > How do I get the PI at the top where I want it? I'm using Activetcl-8.3.4.3 > with tclxml-2.2 and tclxml-2.0, and neither seem to give the result I'm after > the way I'm doing it. > -- 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 |