I am glad it worked out.
You can use the DOM methods to find a <g> and test if it is empty (it will have no child). In that case, you can remove it from the tree.
Vincent.
Karen Chen wrote:
Thanks Vincent! I am now able to get both the contents in. Here's my output:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 20001102//EN' 'http://www.w3.org/TR/2000/CR-SVG-20001102/DTD/svg-20001102.dtd'>
<svg style="fill-opacity:1; color-rendering:auto; color-interpolation:sRGB; text-rendering:auto; stroke:black; stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto; stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal; stroke-width:1; font-family:'sansserif'; font-style:normal; stroke-linejoin:miter; font-size:12; stroke-dashoffset:0; image-rendering:auto;" width="2147483647" height="2147483647">
<!--Generated by the Batik Graphics2D SVG Generator-->
<defs id="genericDefs" />
<g />
<title>Cases
</title>
<description>Current diagram:
1) Cases
</description>
<g>Other codes for defining the image positions.. generated by the generator </g>
</svg>
The minor problem I'm facing is, how can I get rid of the empty <g /> just below the <defs id="genericDefs" /> at the top?
What i am doing now is to remove the top level group and then appending it to the document again (so it will be placed below the 'title' and 'desc' tags).
Element topLevelGrp = svgGenerator.getTopLevelGroup();
svgRoot.appendChild(topLevelGrp);
Is it possible in any way for me to get rid of the <g /> above the <title> ??
Thanks for your help!
Cheers,
Karen
----- Original Message -----
From: "Vincent Hardy" <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
To: "Batik Users" <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
Sent: Thursday, January 23, 2003 5:54 AM
Subject: Re: How to add an element before generating the SVG image?
> Hello Karen,
>
> After you get the root, you should use one of the following two methods
> to write out your content:
>
> stream(Element svgRoot, java.io.Writer writer, boolean useCss)
> or
> stream(Element svgRoot, java.io.Writer writer)
>
> By default, getRoot causes the SVGGraphics2D to reset its content, so if
> you stream without passing the previously retrieved root, SVGGraphics2D
> just streams out the new, empty content.
>
> Vincent.
>
> Karen Chen wrote:
> > Hi,
> > I would like to add some new elements (<title> and
> > <description>)before I generate the xml file using the SVGGraphics2D.
> > A desired output would be:
> > > > <?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 >
> > <title>Title for the generated image</title>
> > <desc>Image description</desc>
> > <!--Generated by the Batik Graphics2D SVG Generator-->
> > <defs id="genericDefs" />
> > <g />
> > //... generated image contents
> > <g />
> > </svg>
> > I have tried using the getRoot() method from the SVGGraphics2D class,
> > added some elements and tried to generate the svg file, but the codes to
> > describe the images just disappeared and became empty tags. I haven't
> > got any idea how to resolve the problem and why it happens this way. Can
> > someone who has solved this problem before provide some help?
> > > > The resultant code i got after manipulating the Element I get from the
> > getRoot() method was:
> > > > <?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="fill-opacity:1; color-rendering:auto;
> > color-interpolation:auto; text-rendering:auto; stroke:black;
> > stroke-linecap:square; stroke-miterlimit:10; shape-rendering:auto;
> > stroke-opacity:1; fill:black; stroke-dasharray:none; font-weight:normal;
> > stroke-width:1; font-family:'sansserif'; font-style:normal;
> > stroke-linejoin:miter; font-size:12; stroke-dashoffset:0;
> > image-rendering:auto;" xmlns="http://www.w3.org/2000/svg" width="591"
> > xmlns:xlink="http://www.w3.org/1999/xlink" height="498">
> > <!--Generated by the Batik Graphics2D SVG Generator-->
> > <defs id="genericDefs" />
> > <g />
> > </svg>
> > Thanks in advance!
> > > > Karen Chen
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
>
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
