I have loaded an SVG file into memory in javascript.
I want to manipulate this data in memory using the Javascript replace function.
As you notice, there are many 'g' elements. I want to wrap them all into a new g element with an id called 'viewport'.
This is the svg (source):
<!--?xml version="1.0" ?-->
<svg xmlns="http://www.w3.org/2000/svg" width="822" height="600">
<defs>
....
</defs>
<g id="edges" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
<g class="null current-task" id="S02" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
<g id="S04" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
</svg>
And this is how it should be:
<!--?xml version="1.0" ?-->
<svg xmlns="http://www.w3.org/2000/svg" width="822" height="600">
<defs>
....
</defs>
<g id="viewport">
<g id="edges" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
<g class="null current-task" id="S02" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
<g id="S04" transform="translate(245.296 61.75) scale(0.630539)">
....
</g>
</g>
</svg>
How can this be done using Javascript and Regex (replace function?)?