Hi Loicrollus, [EMAIL PROTECTED] wrote on 04/20/2007 08:29:01 AM:
> But in my software, I need to add a lot of new svg elements from a > String. I can put all of the data in Node (newElement). I try to add > this node to the newLayer element. Then to add the newLayer element > to the g1 element (a kind of root element, the son of the svg element) > I try this: > > String svgNS="http://www.w3.org/2000/svg"; > Element newLayer = document.createElementNS(svgNS, "g"); > newLayer.setAttribute("id","123"); > newLayer.appendChild(document.importNode(newElement,true)); //add the new node > g1.appendChild(newLayer); //add the new layer in the <g id="1"> element > > The Jsvgcanvas doesn't refresh, but when I save the document into a > file, the document is ok: Your elements in the external document aren't in the SVG namespace. You should add the attribute: xmlns="http://www.w3.org/2000/svg" to the root of the SVG you are importing. Then the XML parser will put them in the SVG Namespace so they will show up when you import them into the SVG Document. > > <svg ...> > <g id="1"> > ... > <g id="123"> > <g id="layer101"> > <polyline style="fill:none; stroke:rgb(255,000,000);" points="8325 > 2232, 8325 2540"/> > <polyline style="fill:none; stroke:rgb(255,000,000);" points="7925 > 2232, 7925 2540"/> > <polyline style="fill:none; ... > </g> > </g> > </g> > </svg> > > The file is ok, when I load it in a new Jsvgcanvas, it shows the > picture with the new elements > > > So I think that I have a bad using of createElementNS. > > I try: > > String svgNS=" http://www.w3.org/2000/svg"; > Element group = document.createElementNS(svgNS, "g"); > Element rect = document.createElementNS (svgNS, "rect"); > rect.setAttributeNS(null, "x", "1200"); > rect.setAttributeNS(null, "y", "2200" ); > rect.setAttributeNS(null, "width", "3100"); > rect.setAttributeNS(null, "height", "3510"); > rect.setAttributeNS(null, "style", "stroke: red; fill: red;"); > group.appendChild(rectangle); > a1.appendChild(group); > > It works > > But this (the same without namespace for the child): > > String svgNS="http://www.w3.org/2000/svg"; > Element group = document.createElementNS (svgNS, "g"); > Element rect = document.createElement ("rect"); > rect.setAttribute( "x", "1200"); > rect.setAttribute("y", "2200" ); > rect.setAttribute("width", "3100"); > rect.setAttribute("height", "3510"); > rect.setAttribute("style", "stroke: red; fill: red;"); > group.appendChild(rect); > a1.appendChild(group); > > It doesn't works. > > > But in my project, I need to add new elements thanks to a new Node > which come from an other document (which have element from a file or > a servlet). So I cannot put createElementNS for each element! > > Is there a way to specify the namespace for a Node (and for all > children) which already exists? How can I do to add a new node with > a lot of new elements and to refresh the jsvgcanvas? > > -- > This message was sent on behalf of [EMAIL PROTECTED] at openSubscriber.com > http://www.opensubscriber.com/messages/[EMAIL PROTECTED] > apache.org/topic.html > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
