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)?
Rather than struggle with Batik over
DOCTYPE
generation, just skip it. As Robert commented, it's generally ignored. Furthermore, using aDOCTYPE
is not recommended with SVG: