Hi Cameron
first, thank you for your help.

I did exactly what you said, but it does not work, the message i got is the following:

org.apache.batik.script.InterpreterException: invalid argument count (<SVG>; line 1)
        at org.apache.batik.script.rhino.RhinoInterpreter.evaluate(Unknown 
Source)
        at FSheet.FSBibSymboles.readFile(FSBibSymboles.java:249)


my code:

String xml= "<polygon fill=\"none\" points=\"243.0,320.30127 193.0,320.30127 168.0,277.0 193.0,233.69873 243.0,233.69873 268.0,277.0\" stroke=\"#000000\"/>";

Interpreter in = getFSCanvas().getInterpreter("text/ecmascript");

SVGDocument doc = getFSCanvas().getSVGDocument();

try {
                Node n = (Node)in.evaluate("parseXML('"+xml+"')");
                doc.getDocumentElement().appendChild(n);
                        }
        catch(Exception ex) {
                ex.printStackTrace();
        }


Where getFSCanvas() returns my current JSVGCanvas:
public class MyJSVGCanvas extends JSVGCanvas {

    /**
     * Returns an Interpreter for the currently loaded document.
     */
    public Interpreter getInterpreter(String type) {
      return bridgeContext.getInterpreter(type);
    }
  }

Regards

BadrEddine



From: Cameron McCormack <[EMAIL PROTECTED]>
Reply-To: [email protected]
To: [email protected]
Subject: Re: adding svg code to SVGDocument
Date: Thu, 7 Jul 2005 11:34:39 +1000

Hi Badreddine.

badreddine lakhlifi:
> i would like to know if there is a way(a method...) to add an element to an
> SVGDocument when the element is given as a string of SVG code.
>
> for example:
> String Code = "<polygon  fill=\"none\" points=\"240.0, 243.0,.........\"
> stroke =\"#000000\"/>"
> SVGDocument doc = mycanvas.getSVGDocument();
> doc.getDocumentElement().appendChild(   myMethod(Code)  );

Yes there is.  You can use the (de facto standard) parseXML function.
This is usually used from script, and unfortunately I can't see a way to
access the Window object to get at the parseXML method without
evaluating some script.  So you could perhaps do the following.  I
extend the JSVGCanvas here to get access to the script interpreter:

<untested-code>
  import org.apache.batik.script.Interpreter;

  // ...

  public class MyJSVGCanvas extends JSVGCanvas {

    /**
     * Returns an Interpreter for the currently loaded document.
     */
    public Interpreter getInterpreter(String type) {
      return bridgeContext.getInterpreter(type);
    }
  }

  // ...

String xml = "<polygon fill=\"none\" points=\"240.0, 243.0, ...\" stroke=\"#000000\"/>";
  Interpreter in = mycanvas.getInterpreter("text/ecmascript");
  Node n = (Node) in.evaluate("parseXML('" + xml + "')");
  SVGDocument doc = mycanvas.getSVGDocument();
  doc.getDocumentElement().appendChild(n);
</untested-code>

Cameron

--
  e-mail : cam (at) mcc.id.au           icq : 26955922
     web : http://mcc.id.au/            msn : cam-msn (at) aka.mcc.id.au
  office : +61399055779              jabber : heycam (at) jabber.org

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


_________________________________________________________________
Bénéficiez de 250 Mo de stockage avec MSN Hotmail http://g.msn.fr/FR1001/866


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

Reply via email to