Ok after lot of search I decided to ask question here. Below is the sample code to reproduce my problem. The document object is build with chinese character.
String value= "";
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("value");
root.setAttribute("attribute", value);
doc.appendChild(root);
DOMSource source = new DOMSource(doc);
I am trying to convert the document source to string using the Transformer class with the below code.
ByteArrayOutputStream outStream = null;
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StreamResult htmlStreamResult = new StreamResult( new ByteArrayOutputStream() );
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.transform(source, htmlStreamResult);
outStream = (ByteArrayOutputStream) htmlStreamResult.getOutputStream();
String outPut = outStream.toString( "UTF-8" );
But I got output with converted Chinese characters as below.
<?xml version="1.0" encoding="UTF-8" standalone="no"?><value attribute="𧀠"/>
I do not want the Chinese character to be converted but to be displayed as it is. Appreciate if anyone help me on this.