Does anyone know how to correctly output extended characters (not BMP, more than 1 char ) using Java XMLStreamWriter? For example, trying to output Unicode U + 10480 π :
import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; public class XmlStreamWriterExtendedCharactersFail { public static void main(String[] args) throws XMLStreamException { String inlineStr = "inlineStr = π";
leads to:
sbStr = π <?xml version="1.1" encoding="UTF-8"?><el>sbStr = ��</el>
Please note that �� are invalid code points and lead to an error when parsing with SAX.
Expected Result:
sbStr = π <?xml version="1.1" encoding="UTF-8"?><el>sbStr = π</el>
sbStr = ⣰ will also do this as a last resort, but the first is preferable.
source share