Eric Hodges wrote: > > > In DOM Level 2, you first need to create the doctype node with > > DOMImplementation.createDocumentType() and then create the document node > > with DOMImplementation.createDocument() to which you pass the doctype. > > You can't change the doctype afterwards. > > Wow, that's a serious limitation. I'm trying rebuild an XML document from a > database (and also rebuild them from serialized objects). I usually don't > know the document type until sometime after I've created the document. > > I guess I'll have to use some sort of lazy construction. Why is DOM so > screwy?
The problem is that depending on the type of document the application deals with the implementation may use very different types of classes. For instance, an SVG or MathML DOM implementation typically uses very different classes of objects for SVG and MathML nodes than a vanilla DOM such as Xerces DOM. In a case where an implementation supports several DOMs at the same time, the switch on which set of classes it uses is triggered at the document creation time, depending on what type of document the application wants to use. DOM Level 2 is designed so that the doctype node is the trigger. However, it is understood that this has serious limitations. In a parser environment such as Xerces for instance, you really want to create the document first and then populate with a vanilla doctype node whenever, and if, you encounter one. I haven't found any way to reconcile the two problems though. Any idea there is very welcome!! -- Arnaud Le Hors - IBM Cupertino, XML Technology Group