xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bishop, Michael W. CONTR J9C880" <Michael.Bis...@je.jfcom.mil>
Subject RE: Write a svg document to a file
Date Thu, 06 Oct 2005 14:41:00 GMT
Looks similar to the way I do it:
 
document.getDocumentElement().appendChild(...);
 
I call Element.setAttribute(...) as opposed to setAttributeNS(...), but that shouldn't be
a problem.
 
For your save routine, are you flushing the FileWriter before closing it?
 
Michael Bishop
 

________________________________

From: julie gautier [mailto:juliegautier@yahoo.fr]
Sent: Thu 10/6/2005 10:38 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: Write a svg document to a file


To add elements to the svgRoot (created from the Document), I write things like that : 
 
Element rect = doc.createElementNS(svgNS, "rect");
rect.setAttributeNS(null, "x", "10");
rect.setAttributeNS(null, "y", "20");
rect.setAttributeNS(null, "width", "50");
rect.setAttributeNS(null, "height", "50");
svgRoot.appendChild(rect);
 
And the document (or I should say the svgRoot) is well streamed to output, so the dom tree
seems to be correctly built...
 
Thanks for your help.
Julie

"Bishop, Michael W. CONTR J9C880" <Michael.Bishop@je.jfcom.mil> a écrit :

	From your original post, it looks like you're using the SVGGraphics2D to create document
fragments. That approach doesn't work well in that the SVGGraphics2D object doesn't render
anything to your document. I ran into that problem myself. You did say you appended everything
to your SVG root element though. The empty file does sound problematic of using the SVGGraphics2D
object and expecting to have elements in your document that may not be there. How are you
adding things? You may want to look up a quick routine to print DOM documents to the screen
so you can see what the DOM tree actually represents.
	
	Michael Bishop
	
	________________________________
	
	From: julie gautier [mailto:juliegautier@yahoo.fr]
	Sent: Thu 10/6/2005 10:09 AM
	To: batik-users@xmlgraphics.apache.org
	Subject: RE: Write a svg document to a file
	
	
	Thanks for your answer. I tr ied your suggestion : I wrote :
	
	org.apache.batik.dom.util.DOMUtilities.writeDocument(doc, new FileWriter("c:\\test.svg"));
	
	where doc is the Document described in the example below.
	But it doesn't work : the svg file created is empty. Do you know why ?
	As I created the svg document by appending everything to the svgRoot element, I also tried
as follow : 
	
	org.apache.batik.dom.util.DOMUtilities.writeDocument(svgRoot.getOwnerDocument(), new FileWriter("c:\\test.svg"));
	
	but it failed too.
	Do you know what to do ?
	Thanks again.
	Julie
	
	
	"Bishop, Michael W. CONTR J9C880" a écrit :
	
	In my application I simply used org.apache.batik.dom.util.DOMUtilities.writeDocument(SVGDocument,
FileWriter);
	
	Michael Bishop
	
	________________________________
	
	From: julie gautier [mailto:juliegautier@yahoo.fr]
	Sent: Thu 10/6/2005 7:52 AM
	To: batik-users@xmlgraphics.apache.org
	Subject: Write a svg do cument to a file
	
	
	Hi,
	I use Batik to create a svg document and display it on a window. For that I use the above
code :
	
	public ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response) throws Exception {
	...
	/*creation of the svg document */
	
	DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
	String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
	Document doc = impl.createDocument(svgNS, "svg", null);
	SVGGraphics2D svgGenerator = ne w SVGGraphics2D(doc);
	
	Element svgRoot = svgGenerator.getRoot();
	
	/*insert svg into the document*/
	...
	
	/*send to output*/
	java.io.OutputStream out = response.getOutputStream();
	boolean useCSS = false;
	Writer wout = new OutputStreamWriter(out, "iso-8859-1");
	svgGenerator.stream(svgRoot, wout);
	}
	
	
	This works fine. My problem is to send the "svgRoot" to a file on the server. Here is my
cod e : 
	
	BufferedWriter bw = new BufferedWriter(new FileWriter("c:\\test.svg"));
	svgGenerator.stream(svgRoot, bw);
	bw.close();
	
	The document test.svg is created but when I try to open it I have an error : the first line
is : 
	"" instead of "" and I'm not able to open the file.
	
	
	
	What should I do ?
	
	
	
	Thanks in advance.
	
	
	
	Julie
	
	________________________________
	
	Appel audio GRATUIT partout dans le monde avec le nouveau Y ahoo! Messenger
	Téléchargez le ici ! 
	---------------------------------------------------------------------
	To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
	For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
	
	________________________________
	
	Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
	Téléchargez le ici ! 
	---------------------------------------------------------------------
	To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
	For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org

________________________________

Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger
Téléchargez le ici ! <http://us.rd.yahoo.com/messenger/mail_taglines/default/*http://fr.messenger.yahoo.com>
 

Mime
View raw message