[webkit-dev] Why it is not possible to appendChild on elements created by DOMParser?

Alexander Shabanov avshabanov at gmail.com
Sat Nov 28 03:16:26 PST 2009


Hi all,

Sorry for silly question but I think that it might be a nice feature to webkit.
The following code works in Mozilla Firefox 3.5, but it does not work
in webkit-based browsers:

        var parser = new DOMParser();
	var str = "<p>This is a test</p>";
	var doc = parser.parseFromString(str, "text/xml");
	document.body.appendChild(doc.documentElement.firstChild);

I found that specification to DOMParser does not guarantee that the
result of DOMParser's parseFromX methods can
be directly used in the original document.
Nevertheless I believe that it would be quite a useful feature, at
least it won't require JS code to create DOM-compliant content from
the parsed one.
May be I missed something and webkit offers a way of quick adaptation
of the parsed content to the original DOM tree?
Thanks in advance.

P.S.: even though Firefox provides such a feature, a style
specification in the following code will take no effect:
        var parser = new DOMParser();
	var str = "<p style='color: red;'>This is a test</p>";
	var doc = parser.parseFromString(str, "text/xml");
	document.body.appendChild(doc.documentElement.firstChild);

-- 
Best regards,
    Alexander Shabanov


More information about the webkit-dev mailing list