The moose likes XML and Related Technologies and the fly likes Transformer - omitting the xml header ( Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Transformer - omitting the xml header (" ?xml encoding=.. ?" )" Watch "Transformer - omitting the xml header (" ?xml encoding=.. ?" )" New topic

Transformer - omitting the xml header (" ?xml encoding=.. ?" )

Sol Mayer-Orn
Ranch Hand

Joined: Nov 13, 2002
Posts: 311

I'm trying to use Transformer in order to convert a DOM Node into a string.
This works, but unfortunately it sticks the xml header at the beginning of the string : < ?xml ... >
For my particular application, I don't need this xml header. So how do you tell the transformer to avoid printing it ?

That's my code so far:

Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

If you were doing an XSLT transformation, then you would use <xslutput omit-xml-declaration="yes"/>. So in your code I would tryThat's my best guess.

Bear in mind that the transformer cannot omit the XML declaration unless the encoding of the document it is writing is UTF-8. Any other encoding has to be specified in an XML declaration.
[ February 05, 2006: Message edited by: Paul Clapham ]
It is sorta covered in the JavaRanch Style Guide.
subject: Transformer - omitting the xml header (" ?xml encoding=.. ?" )
Similar Threads
XML doument to a string
creating a DOM document from an XML file.
Reading child tags as separate xml blocks
What Replaced org.apache.xml.serialize.XMLSerializer and org.apache.xml.serialize.OutputFormat
Inserting node in XMl and retaining doc type information