You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by milof <mi...@gazeta.pl> on 2006/08/18 12:35:12 UTC

editing svg problem

hi,

I'm a beginner with batik library and I need to create a program that would
allow me to edit existing svg files and the save them.

The code that I have written so far doesn't seem to be working. My program
doesn't want to access my svg file, however there are no erros when i
execute it.

public void editSVG (String inputFilename) throws Exception {
    
		DOMImplementation impl = SVGDOMImplementation.getDOMImplementation();
		String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
		String svgURI = new File(inputFilename).toURL().toString();
		
		SVGDocument doc;
		try {
		doc = (SVGDocument)impl.createDocument(svgURI, "svg", null);
		
		// get the root element (the svg element)
		Element svgRoot = doc.getDocumentElement();
		
		// set the width and height attribute on the root svg element
		svgRoot.setAttributeNS(null, "width", "400");
		svgRoot.setAttributeNS(null, "height", "450");
				
		// create the rectangle
		Element rectangle = doc.createElementNS(svgNS, "rect");
		rectangle.setAttributeNS(null, "x", "200");
		rectangle.setAttributeNS(null, "y", "200");
		rectangle.setAttributeNS(null, "width", "100");
		rectangle.setAttributeNS(null, "height", "100");
		rectangle.setAttributeNS(null, "fill", "red");

		// attach the rectangle to the svg root element
		svgRoot.appendChild(rectangle);

		} catch (Exception e){
			System.out.println("Error: " + e);
		}
    }

inputFilename is a string with my svg filename (test.svg)

I would be really grateful if somebody could help.
-- 
View this message in context: http://www.nabble.com/editing-svg-problem-tf2126520.html#a5867406
Sent from the Batik - Dev forum at Nabble.com.


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