Re: DOMParser() and SVG

Martin Honnen <[email protected]>
Newsgroups gmane.comp.mozilla.devel.dom
Organization Liberty Development
Message-ID <[email protected]>
elliottcable wrote:
> There's been a short discussion of this topic back in 2006 
> (http://markmail.org/message/2vr63izihzb5nefr), regarding 1.5.0 and the 
> then-current nightlies, but I was curious about the current state of the 
> matter.
> 
> As it is, DOMParser().parseFromString(my_svg_string, "image/svg+xml") 
> will fail out, and replacing the SVG mime type with the plain XML mime 
> type will simply return a  XMLDocument, which I am unable to mix into 
> an existing SVG node nor which can I run getElementById on.

You should be able to use application/xml and then importNode the 
documentElement e.g. in an HTML document

var doc = new DOMParser().parseFromString([
   '<svg xmlns="http://www.w3.org/2000/svg">',
   '<circle cx="100" cy="100" r="20" fill="green"/>',
   '</svg>'
].join('\r\n'), 'application/xml');
document.body.appendChild(document.importNode(doc.documentElement, true));

works just fine. So getElementById does not work but inserting nodes 
into another document should work fine.





-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.