Replacing XML document element

J

Julius Mong

Dear all, I'm trying to download an external SVG document from an SVG doc
and then replace the current SVG with the new SVG DOM by:

function replaceSVG() {
var root = document.getDocumentElement();
while(root.hasChildNodes()) root.removeChild(root.firstChild);
root.appendChild(parseXML(content, document));
}

This works fine as long as the external SVG document contains no <?xml
version="1.0"?> and the resulting SVG would become somehting like <svg the
original><svg the loaded DOM svg elem>...</svg></svg>

I tried directly using:

document.replaceChild(parseXML(content,document),
document.getDocumentElement());

,and,

document.documentElement = parseXML(content,document);

to try to not have the outer <svg> wrapping the loaded svg tree. Neither
works, javascript errors resulted.

I must be missing something here, as I'm sure it can be done, so does anyone
know how I can achieve what I'm trying to? If possible could we deal with
external SVG documents that contain <?xml version="1.0"?> as the 1st line
too?

Thanks, Jules
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,173
Latest member
GeraldReund
Top