hi ben,

well, it works here. although i only tried VERY simple svg documents.
what's the exception you're getting? what's your jdk?

.rm


csanfeb schrieb:
Thanks again!

Hmmm... for some reason that bombs out on f.createDocument(null, is);

Ben


Ruben Malchow wrote:

hi ben,

sorry, i didn't test it, i only meant to give you a general idea (i.e. that you can create documents from any input stream). and so i forgot a few little things ....

the full code would be:

------------ SNIP ------------

import java.io.ByteArrayInputStream;
import java.io.InputStream;

import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.util.XMLResourceDescriptor;
import org.w3c.dom.svg.SVGDocument;


public class Simple {

        
   public static void main(String[] args) {
      try {
        String svgStr = "<svg></svg>";
        InputStream is= new ByteArrayInputStream(svgStr.getBytes());
        String parser = XMLResourceDescriptor.getXMLParserClassName();
        SAXSVGDocumentFactory f = new
        SAXSVGDocumentFactory(parser);
        SVGDocument doc = (SVGDocument)f.createDocument(null, is);
     } catch (Exception e) {
     }
   }
        
}

------------ SNIP ------------


csanfeb schrieb:
Hey Ruben,

Thanks for the input! Unfortunatally, for some reason, I can't get this
to
compile. It doesn't like ByteInputStream. What imports did you use? Would
it
be possible to show me this in a simple standalone project?

Thanks,

Ben

Ruben Malchow wrote:

hi ben,

maybe it's possible for you to try this:


        String svgStr = "<svg>bla[...]</svg>";

        InputStream is= new ByteInputStream(svgStr.getBytes());

        SVGDocument doc =SAXDocumentFactory.createSVGDocument(null, is);


but since you have no uri, it'll barf when it tries to resolve relative links (as in, for example, references to external bitmap images). if it's just plain svg grphics with no external references, you should be fine ...

.rm




csanfeb schrieb:
I've got an unusual question that I've been having a difficult time
finding
an answer to...

I want to create a svg on the fly for putting onto a JFramel. Strange
part
is I want to create the svg based off a string such as follows:

String theString = "<?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
xmlns:xlink=\"http://www.w3.org/1999/xlink\"; 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:&apos;Dialog&apos;;
font-style:normal; stroke-linejoin:miter; font-size:12;
stroke-dashoffset:0;
image-rendering:auto;\" xmlns=\"http://www.w3.org/2000/svg\";><defs
id=\"genericDefs\" /><g><text xml:space=\"preserve\" x=\"10\" y=\"30\"
style=\"stroke:none;\">My Text...</text></g></svg>";

I figured out one way to do this,
        try {
            // Create temp file.
            File temp = File.createTempFile("pattern", ".suffix");
// Delete temp file when program exits.
            temp.deleteOnExit();
// Write to temp file
            BufferedWriter out = new BufferedWriter(new
FileWriter(temp));
out.write(theString);
            out.close();
        } catch (IOException e) {

Now I am trying to figure out a way to do this without creating a temp
file.
Does anybody know a way to do this?

Thanks.

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



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






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

Reply via email to