03-28-2010 09:09 PM
I've looked at the docs and spent the afternoon looking around the web and can't seem to figure this out. It is a combination SAX parser and java.io question. The SAX parser will take either an InputStream or an InputSource, but I can't seem to find out how to turn a String containing XML into either of these to pass to the parser. Anyone know how to do this?
Solved! Go to Solution.
03-28-2010 11:08 PM
Unless you know that the XML is encoded as ISO-8859-1 (the default encoding for getBytes), you should use getBytes("UTF-8") (or some other encoding, if you know otherwise). The default encoding for XML is UTF-8.
The two encodings agree for the first 128 characters (ASCII 0-127), but after that, watch out! (Try your code with XML text that contains, for instance, a copyright symbol, ©, or an accented vowel, as in "à la carte".)
03-29-2010 08:54 AM
Hey, Ted! Thanks for the reply. The application more or less ensures that the encoding will be UTF-8. I'm serializing a String that represents an XML encoding of app defaults, then, when the app starts up again, reads it to get the default information. In this case, I'm not reading anything I didn't write, so I have control over both sides.