Hi Jan.

Jan Tošovský:
> I've already tried many combinations but still without success. Has
> anybody small piece of working code for dynamic creation of SVG with
> setting of xml:base?

Attached is a test program that creates an SVG document and sets an HTTP
URL as the xml:base="" on the root <svg> element, so that an <image>
element’s relative URL is resolved against it.

-- 
Cameron McCormack ≝ http://mcc.id.au/
import org.apache.batik.dom.svg.*;
import org.apache.batik.swing.*;
import org.w3c.dom.*;
import org.w3c.dom.svg.SVGDocument;
import java.awt.*;
import javax.swing.*;

public class BaseTest {
    private static String SVGNS = "http://www.w3.org/2000/svg";;
    private static String XMLNS = "http://www.w3.org/XML/1998/namespace";;
    private static String XLINKNS = "http://www.w3.org/1999/xlink";;

    public static void main(String[] args) {
        try {
            final SVGDocument d = (SVGDocument) SVGDOMImplementation.getDOMImplementation().createDocument(SVGNS, "svg", null);
            Element svg = d.getDocumentElement();
            svg.setAttributeNS(XMLNS, "xml:base", "http://www.google.com/";);
            svg.setAttribute("viewBox", "0 0 100 100");
            Element img = d.createElementNS(SVGNS, "image");
            img.setAttribute("width", "100");
            img.setAttribute("height", "100");
            img.setAttributeNS(XLINKNS, "xlink:href", "/images/nav_logo4.png");
            svg.appendChild(img);

            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    JFrame f = new JFrame("xml:base test");
                    JSVGCanvas c = new JSVGCanvas(null, false, false);
                    f.getContentPane().add(c);
                    f.setSize(400, 300);
                    f.setVisible(true);
                    c.setSVGDocument(d);
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to