You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Vl...@bmo.com on 2002/05/02 23:29:48 UTC

how to modify DOCTYPE node in an existing document?

I need to change/assign DTD in a DOM object, so I'm creating a new 
document with a doctype I need and copying all the children of the root 
node. Does anybody know if there is a better and less expensive way to 
modify or set DOCTYPE in an existing document?

Thanks in advance,
Vlad

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: how to modify DOCTYPE node in an existing document?

Posted by Elena Litani <el...@ca.ibm.com>.
Vlad.Epshtein@bmo.com wrote:
> I need to change/assign DTD in a DOM object, so I'm creating a new
> document with a doctype I need and copying all the children of the root
> node. Does anybody know if there is a better and less expensive way to
> modify or set DOCTYPE in an existing document?

The doctype is just the first child of the document (for wellformness
reasons it must appear before documentElement). 
So the following trick will do:
1. document.removeChild (document.getDoctype())
2. create a new doctype using DOMImplementation
3. document.insertBefore (newDoctype, document.getDocumentElement())

However, this trick will only work with the latest code from CVS for
Xerces2 (thanks to Arnaud Le Hors).
You may try it for Xerces 1, however you might get exception..

Hope it helps,
-- 
Elena Litani / IBM Toronto

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org