Thanks to Jason & Paul for their responses. I tried Jason's
suggestion for my example, and it works great. (And I realize
that this question is increasingly off-topic, please forgive me.)<br>
<br>
In my real-world problem, I'm not writing to System.out, I'm writing to
an output stream returned from an HttpsURLConnection. So I tried
this:<br>
<br>
Document doc = getXML();<br>
XMLOutputter out = new XMLOutputter();<br>
out.setEncoding("UTF-8");<br>
String renderedDoc = out.outputString(doc);<br>
<br>
// Construct the request headers<br>
setupHeaders(theConnection, renderedDoc.length());<br>
<br>
// Send the request<br>
OutputStream output = theConnection.getOutputStream();<br>
out.output(doc, output);<br><br>
I don't have access to the server on the other end of that connection,
and the connection is encrypted, so I can't just put in a proxy server
to capture the stream to see what's really being sent.<br>
<br>
One more data point, which may or may not be important. I have to
use the Beta-7 version of JDOM, because it's distributed as part of my
app server, and putting jdom 1.0 earlier in the classpath causes the
app server to choke. <br>
<br>
Many, many thanks for any help.<br>
<br>
-Chris<br>
<br><div><span class="gmail_quote">On 5/20/05, <b class="gmail_sendername">Jason Hunter</b> <<a href="mailto:jhunter@xquery.com">jhunter@xquery.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You're not actually outputting the file to a byte stream. You're<br>outputting it to a String, then printing the string using<br>System.out.println(). System.out is a PrintStream and per the<br>PrintStream Javadocs, "All characters printed by a PrintStream are
<br>converted into bytes using the platform's default character encoding."<br><br>Try this: out.output(doc, System.out);<br><br>That way JDOM gets to control the bytes being output.<br><br>-jh-<br><br>Chris Curvey wrote:
<br><br>> Hi all,<br>><br>> I'm having a little trouble figuring out utf-8 encoding with JDom. The<br>> output from this sample program is returning a single hex value, \xc9<br>> for an E-acute, but according to this page
<br>> <a href="http://www.fileformat.info/info/unicode/char/00c9/index.htm">http://www.fileformat.info/info/unicode/char/00c9/index.htm</a>, the UTF-8<br>> encoding for E-acute should be a hex pair \xc3 and \x89. (\xc9 appears
<br>> to be right value for UTF-16.)<br>><br>> Any idea what I'm doing wrong? Or am I just misinterpreting something?<br>><br>> import org.jdom.Document;<br>> import org.jdom.Element;<br>> import org.jdom.output.XMLOutputter
;<br>> import org.jdom.output.Format;<br>><br>> class JdomTest<br>> {<br>> public static void main (String[] argv)<br>> {<br>> Document doc = new Document();<br>> Element element = new Element("foobar");
<br>> element.setText("CLOISONNÉ");<br>> doc.addContent(element);<br>><br>> Format format = Format.getPrettyFormat();<br>> format.setEncoding("UTF-8");<br>
> XMLOutputter out = new XMLOutputter(format);<br>> System.out.println(out.outputString(doc));<br>> }<br>> }<br>><br>><br>> ------------------------------------------------------------------------
<br>><br>> _______________________________________________<br>> To control your jdom-interest membership:<br>> <a href="http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com">http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com
</a><br></blockquote></div><br>