You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Jonas Ruesch <jo...@gmx.net> on 2003/12/03 22:14:55 UTC

how to pass a normal DOM Document to JSVGCanvas with setSVGDocument?


I use Xindice to store some SVG Documents and retrieve them
as a org.w3c.dom.Document, which I now would like to show with JSVGCanvas.setSVGDocument(svgdocu)

I tried:

i)
Document doc = ..//obtained from Xindice. Printed it out when getting it form the DB and is a correct SVG (generated with Sodipodi).
SVGDocument svgDoc;
SVGDOMImplementation impl = (SVGDOMImplementation) 
SVGDOMImplementation.getDOMImplementation();
svgDoc = (SVGDocument) org.apache.batik.dom.util.DOMUtilities.deepCloneDocument(doc, impl); 
// svgDoc.createElementNS("?","?"); // needs to be set correctly? 

This doesn't work. It seems to me after this operation all the attributes of the svg tags are removed??!!
JSVGCanvas says: " The attribute 'width' of the element <rect> is required"
and the this way cloned document looks printed like this:

<?xml version="1.0" encoding="UTF-8"?>
<svg contentScriptType="text/ecmascript" zoomAndPan="magnify" contentStyleType="text/css" id="svg548" sodipodi:docname="/home/yoyo/yoyo/eth/7_sem/semesterarbeit_xml_db/batik/rect.svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" version="1.0" width="210mm" preserveAspectRatio="xMidYMid meet" sodipodi:version="0.32" xmlns:xlink="http://www.w3.org/1999/xlink" height="297mm" xmlns="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" sodipodi:docbase="/home/yoyo/yoyo/eth/7_sem/semesterarbeit_xml_db/batik">
  <defs/>
  <sodipodi:namedview/>
  <rect/>  <---- wrong, was alright in the source Document
</svg>


ii)
DOMImplementation domImpl = SVGDOMImplementation.getDOMImplementation();
document = (SVGDocument)domImpl.createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI, "svg",null);
		
			
DOMResult domResult = new DOMResult(document.getDocumentElement()); //give rootelement to domResult
DOMSource domSource = new DOMSource(node); // known node from the Document
//DOMSource domSource = new DOMSource(srcdoc.getElementsByTagName("svg").item(0));
		
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(domSource, domResult);

doesn't work either..?

iii)
Somebody wrote  the latest batik version JSVGCanvas contains a setDocument that accepts a normal DOM Document. I compiled 1.5 from 3.12.2003, didn't found the function?

After several hours of research....
I would be very,very glad if somebody may give me a hint or a little code-snippet that may help solving this basic problem.

Thanks a lot!

greetings

jonas





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


Re: how to pass a normal DOM Document to JSVGCanvas with setSVGDocument?

Posted by Thomas DeWeese <Th...@Kodak.com>.
Jonas Ruesch wrote:

> 
> I use Xindice to store some SVG Documents and retrieve them
> as a org.w3c.dom.Document, which I now would like to show with JSVGCanvas.setSVGDocument(svgdocu)
> 
> I tried:
> 
> i)
> Document doc = ..//obtained from Xindice. Printed it out when getting it form the DB and is a correct SVG (generated with Sodipodi).

 > This doesn't work. It seems to me after this operation all the 
attributes of the svg tags are removed??!!
 > JSVGCanvas says: " The attribute 'width' of the element <rect> is 
required"
 > and the this way cloned document looks printed like this:

     Looking at the code in Batik, is it possible that the Attr nodes
returned from Xindice always returns 'false' from 'getSpecified()'?
This would cause exactly this sort of behaviour.

> doesn't work either..?

    Does this also produce a document w/o attributes?

> iii)
> Somebody wrote  the latest batik version JSVGCanvas contains a setDocument 
> that accepts a normal DOM Document. I compiled 1.5 from 3.12.2003, didn't 
> found the function?

    The actual definition is in batik.swing.svg.JSVGComponent.

    Of course the implementation of this uses the same DOMUtilities
method to make a Batik DOM from the generic DOM.

> After several hours of research....
> I would be very,very glad if somebody may give me a hint or a little 
> code-snippet that may help solving this basic problem.

    Well you could copy the code from 
batik.dom.AbstractDocument.importNode and remove the check on
getSpecified() or fix Xindex's DOM (assuming I right above).




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