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.
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.
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.
You need a DOMImplementation object. See the section Bootstrapping.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With