Hallo people!
Thanks to everyone who made it possibile to have such a cool batik project!!!
I am new to batik/svg and I am having a small problem (Maybe I didn't
get the overal taxonomy of the DOM system).
I am trying to modify several nodes of a SVG file and then save the
modified version of the file in another svg.

I am using on a Node n the following method, Node
n=svg.getFirstChild() and using several time n.getNextSibling()
n.getAttributes().getNamedItem("style").setNodeValue("NEWVALUE");

It actually modifies the node if I read it again with
n.getAttributes().getNamedItem("style").getNodeValue()

When I save it, I get a non vlaid svg file (svg file at the bottom of the mail).
What is it wrong?
Thank you a lot!
Fortunato

Here the code

/* START CODE*/
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.svggen.SVGGraphics2D;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.Element;
import org.w3c.dom.svg.SVGDocument;
public  class TestSaveSVG {
        public static void main(String [] args){
                SVGDocument doc;
                Element svg;
                try{
                        String parser = 
XMLResourceDescriptor.getXMLParserClassName();
                        SAXSVGDocumentFactory f = new 
SAXSVGDocumentFactory(parser);
                        File fil = new File("Rectangle.svg");
                        doc = (SVGDocument) 
f.createDocument(fil.toURI().toString());
                        svg = doc.getDocumentElement();

// Modify a node of svg using the procedure above

                        // Create an instance of the SVG Generator.
                        SVGGraphics2D svgGenerator = new SVGGraphics2D(doc);

                        // Finally, stream out SVG to the standard output using
                        // UTF-8 encoding.
                        boolean useCSS = true; // we want to use CSS style 
attributes

                        Writer out = new OutputStreamWriter(new 
FileOutputStream("modified.svg"));
                        svgGenerator.stream(out, useCSS);
                        out.close();
                }catch(Exception e){e.printStackTrace();}
        }
}
/*END CODE*/

***********************************************************************Rectangle.svg

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
   xmlns:svg="http://www.w3.org/2000/svg";
   xmlns="http://www.w3.org/2000/svg";
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape";
   version="1.0"
   width="744.09448"
   height="1052.3622"
   id="svg2">
  <defs
     id="defs4">
    <pattern
       patternUnits="userSpaceOnUse"
       width="2"
       height="1"
       patternTransform="translate(0,0) scale(10,10)"
       id="Strips1_1"
       inkscape:stockid="Stripes 1:1">
      <rect
         style="fill:black;stroke:none"
         x="0"
         y="-0.5"
         width="1"
         height="2"
         id="rect3875" />
    </pattern>
  </defs>
  <g
     id="layer1">
    <rect
       width="474.28571"
       height="308.57144"
       x="128.57143"
       y="169.50504"
       id="Oggetto1"
       
style="fill:url(#Strips1_1);fill-opacity:1;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:1,
3;stroke-dashoffset:0;stroke-opacity:1" />
    <rect
       width="505.71429"
       height="340"
       x="128.57143"
       y="669.50507"
       id="rect4635"
       
style="fill:#ffff00;fill-opacity:1;stroke:none;stroke-width:1;stroke-miterlimit:4;stroke-dasharray:1,
3;stroke-dashoffset:0;stroke-opacity:1" />
  </g>
</svg


***********************************************************************MODIFED.svg
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>
<svg style="stroke-dasharray:none; shape-rendering:auto;
font-family:&apos;Dialog&apos;; text-rendering:auto; fill-opacity:1;
color-interpolation:auto; color-rendering:auto; font-size:12;
fill:black; stroke:black; image-rendering:auto; stroke-miterlimit:10;
stroke-linecap:square; stroke-linejoin:miter; font-style:normal;
stroke-width:1; stroke-dashoffset:0; font-weight:normal;
stroke-opacity:1;" xmlns="http://www.w3.org/2000/svg";
contentScriptType="text/ecmascript" preserveAspectRatio="xMidYMid
meet" xmlns:xlink="http://www.w3.org/1999/xlink"; zoomAndPan="magnify"
version="1.0" contentStyleType="text/css"
><!--Generated by the Batik Graphics2D SVG Generator--><defs id="genericDefs"
  /><g
/></svg
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to