You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Kai Hennig <kh...@pobox.com> on 2008/02/24 20:00:05 UTC

How to omit XML Declaration?

Hello,

I want to include an inline SVG (created with Batik) into an XHTML  
page (via a custom JSF component). Unfortunately there is an XML  
Declaration (something like <?xml version="1.0" encoding="utf-8"?>)  
at the beginning of the SVG output of SVGGraphics2D.stream() which is  
not allowed inside an XHTML document (except in the first line of the  
doc of course).

Is there an easy way to prevent the XML Declaration from getting  
written to the stream? I can't find an easy way to do so. What I am  
doing now is a time-consuming identity transformation of the SVG with  
the xsl-output parameter omit-xml-declaration set to "yes".

Here is a sample code (without the identity transformation workaround)

public void encodeBegin(FacesContext context)
     throws SVGGraphics2DIOException {

     ResponseWriter writer = context.getResponseWriter();
     DOMImplementation domImpl = GenericDOMImplementation
     	.getDOMImplementation();
     Document document = domImpl.createDocument(
     	SVGDOMImplementation.SVG_NAMESPACE_URI, "svg", null);

     SVGGraphics2D g = new SVGGraphics2D(document);
     g.setSVGCanvasSize(new Dimension(180, 50));
     Shape circle = new Ellipse2D.Double(0, 0, 50, 50);
     g.fill(circle);

     g.stream(writer, true);

}

Thank you,
Kai

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: How to omit XML Declaration?

Posted by Cameron McCormack <ca...@mcc.id.au>.
Hi Kai.

Kai Hennig:
> I want to include an inline SVG (created with Batik) into an XHTML  
> page (via a custom JSF component). Unfortunately there is an XML  
> Declaration (something like <?xml version="1.0" encoding="utf-8"?>)  
> at the beginning of the SVG output of SVGGraphics2D.stream() which is  
> not allowed inside an XHTML document (except in the first line of the  
> doc of course).
> 
> Is there an easy way to prevent the XML Declaration from getting  
> written to the stream? I can't find an easy way to do so. What I am  
> doing now is a time-consuming identity transformation of the SVG with  
> the xsl-output parameter omit-xml-declaration set to "yes".
> 
> Here is a sample code (without the identity transformation workaround)

At the moment, no, there’s no easy way to skip the XML declaration.  You
would have to modify XmlWriter.writeDocumentHeader(IndentWriter).  Or,
you could be particularly tricky, and provide your own implementation of
a Writer to SVGGraphics2D.stream(Element,Writer,boolean,boolean) that
discards all characters up to the second occurrence of a '>', thereby
skipping the XML and DOCTYPE declarations. :)

-- 
Cameron McCormack, http://mcc.id.au/
	xmpp:heycam@jabber.org  ▪  ICQ 26955922  ▪  MSN cam@mcc.id.au

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org