Jason, you were spot-on with your original suggestion. I had made
the change to my code, but had forgotten to JAR it up. (After 20
years of programming, why do I still make mistakes like that?)<br>
<br>
Thanks a million.<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;">
Well, just be aware the renderedDoc string there is going to be a<br>character String not a byte stream, so you can't look at it for<br>diagnostics about how the encoding's going.<br><br>The out.output(doc, output) looks like the proper way to send UTF-8
<br>characters. I don't recall if there were any issues with beta7 about<br>this. Beta7 was long, long ago. You may also want to specify the<br>encoding in the HTTP headers you're sending so the receiver will know<br>how to parse the bytes.
<br><br>-jh-<br><br>Chris Curvey wrote:<br><br>> Thanks to Jason & Paul for their responses. I tried Jason's suggestion<br>> for my example, and it works great. (And I realize that this question<br>> 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<br>> 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,
<br>> and the connection is encrypted, so I can't just put in a proxy server<br>> 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
<br>> the Beta-7 version of JDOM, because it's distributed as part of my app<br>> server, and putting jdom 1.0 earlier in the classpath causes the app<br>> server to choke.<br>><br>> Many, many thanks for any help.
<br>><br>> -Chris<br>><br>> On 5/20/05, *Jason Hunter* <<a href="mailto:jhunter@xquery.com">jhunter@xquery.com</a><br>> <mailto:<a href="mailto:jhunter@xquery.com">jhunter@xquery.com</a>>> wrote:
<br>><br>> 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
<br>> 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<br>> UTF-8<br>> > encoding for E-acute should be a hex pair \xc3 and \x89. (\xc9<br>> appears<br>> > to be right value for UTF-16.)
<br>> ><br>> > Any idea what I'm doing wrong? Or am I just misinterpreting<br>> 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>> ><br>> > _______________________________________________<br>> > To control your jdom-interest membership:<br>> ><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>> <<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>><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>