I have an SVG file created in a program like InkScape. I want to load it in Javascript and put it into a SVG object along with other SVG elements.
I'd like to have a function that I can pass a URL, it will fetch that SVG, then return a "g" object grouping everything in the SVG file I loaded.
SVG.LoadXML = function (url, continuation) {
var http = new XMLHttpRequest();
http.open("GET", url, false);
http.send();
textBody = http.responseText;
var g = document.createElementNS(SVG.ns, "g");
g.innerHTML = textBody;
return g;
}
The body of the file being loaded looks something like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE svg PUBLIC [...] >
<svg version="1.1" [...] >
<g>
<defs>
<path id="SVG1ID_1_" [...]
etc.
So, I think what I want to do is open the file as XML, then skip over the first two nodes, enter the second one, and copy all the nodes inside there into my SVG in the document.
This seems like the sort of thing that should be pretty simple and has been implemented a few different ways by a few thousand people already.