Then, I used the 'getNamespaceURI()' method as you suggested:
Element docRoot = svgDoc.getDocumentElement(); //svgDoc is the 'user svg'
System.out.println(svgDoc.getNamespaceURI()); //this returns 'null'
I would really have liked to see what docRoot returned but I suspect that will also return 'null'.
My question is: the 'user' svg document is correctly loaded and displayed by Squiggle... It seems to be a "real" svg: It looks like this:
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" >
<svg height="387" width="475" xmlns:xlink="http://www.w3.org/1999/xlink">>
So this does not explicitly set the default namespace to the svg namespace. When Batik thinks it is loading an SVG file it sets the default namespace to SVG (unless the document explicitly sets the default namespace). This is not the normal behavior of an XML parser. So at this point it becomes an issue of how you are loading the user documents.
The way the canvas creates the document is with the SAXSVGDocumentFactory - this is a document factory that knows it is supposed to produce an SVG document (it also knows about the SVG DTD's and takes a few shortcuts there unless validating). The tricky bit is that the SVG DTD should set the default namespace on the 'svg' element - but once again it may be a matter of how the document is being loaded.
A quick thing to check is adding xmlns="http://www.w3.org/2000/svg" to the svg element.
Sorry, I'm not exactly an XML guru...am I missing anything? Thank you in advance.
Maria Teresa
At 06:15 AM 12/9/2003 -0500, you wrote:
Hi Maria,
maria teresa wrote:
I am having a problem using Batik and I hope you can help me solve it. I have two svg files stored in a certain directory in my hard disk; one of them is a background image, while the other contains all the drawings that two different users dynamically add to the background.
[...]
In order to extract the drawings of a single user, I parse the drawings file and extract only the nodes of interest by means of a node iterator and
a custom filter. Each node extracted is appended to the DOM tree of
the background.
This actually works!
I mean, the svg doc I obtain is exactly how I expected, but it is not rendered correctly: the canvas displays only the background.
I would suspect that the nodes you are getting from the 'overlay' drawing are not in the SVG namespace. It is also possible that the coordinate systems do not line up.
You can find out what namespace the elements from the 'user' document are in with 'getNamespaceURI()'.
Also a few other points,
1) Calling setDocument twice in close succession has only worked relyably very recently. 2) calling setDocumentState should be done before setting the document to have effect. 3) Modifications of the 'currently displayed' document should only be done in the updateManager's runnable queue.
So you might try just commenting out the first 'setDocument' call, this way you can avoid all the above issues.
Any suggestion is really appreciated! Thank you, maria teresa. PS: Here is an excerpt from my code: //f is the background svg file //svgCan the JSVGCanvas
Document svgDoc = parser.parse(f.toURL().toString()); svgCan.setDocument(svgDoc); // cosi'becco Xray "pulito"
svgCan.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
//creating the node iterator: DocumentTraversal trav = (DocumentTraversal)doc; NodeIterator ni = trav.createNodeIterator( doc, NodeFilter.SHOW_ELEMENT, new FilterId(),//my custom filter true);
Element docRoot = svgDoc.getDocumentElement(); //iterate over the elements Node node; while((node = ni.nextNode()) != null){ //adding all the filtered nodes to the background System.out.println(node.getNodeValue()); Node importedNode = svgDoc.importNode(node, true); docRoot.appendChild(importedNode); } svgCan.setDocument(svgDoc); //why this does not work?
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- 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]
