Derek Fountain wrote:
> Can I use createNode to insert a node just where I want one?
>
> I have a DOM representing this:
>
> <test>
> <author>
> Derek Fountain
> </author>
> </test>
>
> and I want this:
>
> <test>
> <author>
> Derek Fountain
> </author>
> <description>
> Test information
> </description>
> </test>
>
> More generally, I want to insert a node as a child of a parent node based on
> critera such as "make this the 2nd child element of parentNode".
>
> Can I do that with createNode? If not, what's the best way?
The trick is making description come after the author element.
The simplistic approach is 'createNode /test/description',
but the new element may be before or after the author element.
Ideally you'd want to be able to do something like:
'createNode /test/*[2][self::description]'
But someone will have to add support to the createNode
method for it to work.
Otherwise, you can use the simple 'createNode /test/description'
call. This returns the DOM node of the newly created element.
Then use the 'appendChild' method to make sure it's at the
end of the child list. For example,
set node [dom::DOMImplementation createNode $doc /test/description]
dom::node appendChild [dom::node parent $node] $node
HTHs,
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
|