batik svg editing problem

Discussion in 'Java' started by milof83@gazeta.pl, Aug 18, 2006.

  1. Guest

    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.
     
    , Aug 18, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brian K
    Replies:
    0
    Views:
    843
    Brian K
    Oct 12, 2003
  2. Brian K
    Replies:
    0
    Views:
    647
    Brian K
    Oct 12, 2003
  3. Mardagg
    Replies:
    0
    Views:
    812
    Mardagg
    May 12, 2006
  4. Mardagg
    Replies:
    0
    Views:
    676
    Mardagg
    May 12, 2006
  5. milof83

    editing svg in batik problem

    milof83, Aug 18, 2006, in forum: Java
    Replies:
    0
    Views:
    376
    milof83
    Aug 18, 2006
Loading...

Share This Page