Christopher,


Doesn't the core:file tag do this already ?


Paul


Christopher W. Farnham wrote:
Is there an elegant way to make sure the XML declaration is included when writing to XMOutput?

I have a factory method a la the core FileTag where I was calling |outputFormat.setSuppressDeclaration(false);

|This didn't work (there was no declaration at the top of my XML files). Finally I ended up hacking
my factory method to do this:
| OutputFormat format = new OutputFormat();
//we can use this line if we want results pretty printed
//format = OutputFormat.createPrettyPrint();
if (xmlDeclaration) {
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>".toCharArray());
}
format.setEncoding( "UTF8" );
format.setSuppressDeclaration(true);
final XMLWriter xmlWriter = new XMLWriter(writer, format);
xmlWriter.setEscapeText(false);


       XMLOutput returnOutput = new XMLOutput() {
           public void close() throws IOException {
               xmlWriter.close();
           }
       };
       returnOutput.setContentHandler(xmlWriter);
       returnOutput.setLexicalHandler(xmlWriter);
       return returnOutput;

|This, of course, is not the best way to do things, but it works. Did I miss something?

Thanks,

Christopher Farnham
Senior Consultant at Wrycan, Inc.

[EMAIL PROTECTED]
http://www.wrycan.com



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to