I create SVG elements (circles) with JavaScript code dynamically. The problem is that I want to pass these circles to a file with .svg extension. If you create the elements in html, it would just copy to the file, past variable position of each. But as they are dynamically created, how can I show them in an svg file so I can then open it with an editing program. Example as a child:
<line title="Vertical" x1=60 y1=60 x2=60 y2=460 stroke-width=2 stroke=black />
And the file to create is:
fwrite($hndl, "<line title='Vertical' x1='60' y1='60' x2='60' y2='460' stroke-width='2' stroke='black' /> \n");
Now with the code dynamically:
for (var i = 0; i < steps; i++) {
var x = stepX * (i + 1);
var y = stepY * (i + 1);
//create circle
var shape = document.createElementNS(
"http://www.w3.org/2000/svg", "circle");
shape.setAttributeNS(null, "cx", originX + x);
shape.setAttributeNS(null, "cy", originY - y);
shape.setAttributeNS(null, "r", 5);
shape.setAttributeNS(null, "fill", "green");
shape.setAttributeNS(null, "class", "draggable");
shape.setAttributeNS(null, "order", i);
shape.setAttributeNS(null, "id", i);
shape.id="circle"+i;
svg.appendChild(shape);
}
How can I pass them to the file?