[jdom-interest] How to specify Unicode for XMLOutputter

Jason Hunter jhunter at acm.org
Thu Aug 2 18:07:58 PDT 2001


Your code is fine.  The issue is that when you pass a Writer to the
output method, you'll have problems if the Writer isn't configured for
the encoding you set.  If you stick to writing to streams or to Strings,
it should be OK.

-jh-

"Woude, Peter van der" wrote:
> 
> Hi,
> 
> I would like to heed the warning given in the documentation of the method
> 'outputString(Document doc)' of XMLOutputter.
> Here it is: "Warning: a String is Unicode, which may not match the
> outputter's specified encoding".
> 
> I can see, then, that I need to change the XMLOutputter's default setting of
> "UTF-8" to "unicode" to match the Java String...?
> 
> I'm not sure how to do this... I just want to make sure that the following
> code works all the time.
> xmlout.setEncoding( "ISO 10646-1" ); <- what to specify in here to make sure
> I'm right
> 
> I haven't tested it to say it "doesn't" work, I just want to be logically
> correct to begin with.
> ...
> Element root = new Element( "root" );
> root.addContent( (new Element( "sub" ) ).setText( "bla" ));
> Document doc = new Document( root );
> // serialize it to a String
> XMLOutputter xmlout = new XMLOutputter();
> xmlout.setEncoding( "ISO 10646-1" ); <- what to specify in here to make sure
> I'm right
> asXML = xmlout.outputString( doc );
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



More information about the jdom-interest mailing list