xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From loicrol...@gmail.com
Subject New Topic
Date Tue, 24 Apr 2007 08:50:54 GMT

I try to add new SVG content to a SVG Document which already exists.

1) I load a svg file with the jsvgcanvas class


2) I get the SVGDocument object which contains DOM tree of the SVG

document = svgCanvas.getSVGDocument();

3) I get a String (=new svg content) from a Servlet

String s = 
"<g id="101" name="test" xmlns="http://www.w3.org/2000/svg">
<polyline points="8325 2232, 8325 2540" style="fill:none; stroke:rgb(255,000,000);"/>
<polyline points="7925 2232, 7925 2540" style="fill:none; stroke:rgb(255,000,000);"/>
<polyline points="7525 2232, 7525 2540" style="fill:none; stroke:rgb(255,000,000);"/>

4) I parse it into a new Document object

InputSource is = new InputSource(new StringReader(s));

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();

Document newLayer = db.parse(is);

5) I add the root element of the new document in the main document

Element root = (Element)document.getDocumentElement();
Node a1 = document.getElementById("1");

Element newLayerRoot = (Element)newLayer.getDocumentElement();

//add the new Layer to the main document
a1.appendChild(document.importNode(b1, true));



The problem is that the JSVGCanvas doesn't refresh!

-When I serialize the main document after the add of the new content, The final document is
If I open load it with the svgcanvas.seturi(), It show me the good picture with the new content.
BUT: There is smth special with the namespace of the g element from the newLayer document.

There is no namespace for this element in the file
<g name="it is the good string" id="101">

-svgCanvas is svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);

-if I try to add a simple rect, it works!: 
String svgNS=" http://www.w3.org/2000/svg";
Element groupe = document.createElementNS(svgNS, "g");
Element rectangle = document.createElementNS (svgNS, "rect");
rectangle.setAttributeNS(null, "x", "1200");
rectangle.setAttributeNS(null, "y", "2200" );
rectangle.setAttributeNS(null, "width", "3100");
rectangle.setAttributeNS(null, "height", "3510");
rectangle.setAttributeNS(null, "style", "stroke: red; fill: red;");

I must add the new element from a String! so I can't create new ElementNS.
I try to add the namespace to the String
"<g id="101" name="test" xmlns="http://www.w3.org/2000/svg">..."

But smth is strange with the namespace:
Element b1 = (Element)newLayer.getDocumentElement(); //b1 is the g element from the string

System.out.println("Element:" + b1.getTagName() + " Name:" + b1.getAttribute("name") + " Namespace:"
+ b1.getNamespaceURI());
//gives me: "Element:g Name:test Namespace:null"


Why getNamespaceURI() gives me "null"? Why when I serialize the document it doesen't show
me any namespace for this element?
How can refresh a JSVGCanvas when I add a new String with a namespace (which disapear during
the parsing...) to a SVGDocument which already exists?


Ps: sorry for my english ;-)

This message was sent on behalf of loicrollus@gmail.com at openSubscriber.com

To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

View raw message