Setting SVG 1.1 doctype (public and system ids) in Batik

175 views Asked by At

I'm trying to get a specific DOCTYPE entry in my SVG output when using Apache Batik (1.14).

A simple example looks like:

        DOMImplementation domImpl = GenericDOMImplementation.getDOMImplementation();
        String svgNS = "http://www.w3.org/2000/svg";
        DocumentType docType = domImpl.createDocumentType("svg", "-//W3C//DTD SVG 1.1//EN", "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd");
        Document document = domImpl.createDocument(svgNS, "svg", docType);
        SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(document);
        SVGGraphics2D svgGenerator = new SVGGraphics2D(ctx, false);
        Writer out = new OutputStreamWriter(System.out, "UTF-8");
        svgGenerator.stream(out, true);

Which produces:

<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.0//EN'
          'http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd'>

I was hoping for something more like:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 
  "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

(based on the SVG 1.1 spec entry at https://www.w3.org/TR/SVG11/struct.html#NewDocument).

How can I get the desired DOCTYPE (ideally without munging the XML afterwards)?

1

There are 1 answers

2
kjhughes On

Rather than struggle with Batik over DOCTYPE generation, just skip it. As Robert commented, it's generally ignored. Furthermore, using a DOCTYPE is not recommended with SVG:

In fact SVG WG members are even telling people not to use a DOCTYPE declaration in SVG 1.0 and 1.1 documents. Instead always include the version and baseProfile attributes on the root <svg> tag, and assign them appropriate values as in the following example.

<svg version="1.1"
     baseProfile="full"
     xmlns="http://www.w3.org/2000/svg"
     xmlns:xlink="http://www.w3.org/1999/xlink"
     xmlns:ev="http://www.w3.org/2001/xml-events">