Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can W3C DOM be used to create Document/DocType nodes?

I'm curious if there is a way to create DocType nodes via W3C DOM? The spec explicitly states that they are readonly and cannot be edited, but are they able to be created?

http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-412266927

The Document interface doesn't seem to have any create method for it:

http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document

Perhaps the broader question is: Can an entirely new HTML Document be built programmatically via DOM? I know about document.createDocumentFragment() but I mean the equivalent of a root HTML document with specific doctype, etc.


Update: it looks like recent Gecko and WebKit implement DOMImplementation.createDocument and DOMImplementation.createDocumentType but not IE8 or before (haven't checked IE9). So unfortunately I'm still stuck there.

I am also a bit unsure what I can do with this new Document instance once I have it. All of the current DOM methods hang off the global document object, so there doesn't seem to be a way to swap it with a new one.

like image 378
mckamey Avatar asked Nov 18 '10 17:11

mckamey


People also ask

What is org W3C DOM document?

Package org. w3c. dom Description. Provides the interfaces for the Document Object Model (DOM) which is a component API of the Java API for XML Processing. The Document Object Model Level 2 Core API allows programs to dynamically access and update the content and structure of documents.

What is DOM implementation?

The DOMImplementation interface represents an object providing methods which are not dependent on any particular document. Such an object is returned by the Document. implementation property.


1 Answers

You need a DOMImplementation object. See the section Bootstrapping.

like image 195
Alohci Avatar answered Sep 21 '22 22:09

Alohci