mercredi 13 juillet 2016

java XML to string issue

tried to solve my xml issue but I have stuct... I am getting xml as System.Out at console quite good, however when I tried to get it returns to me as string it gives me half of xml (returned string is not contains error) but like broken xml. Code like below. (ide: androidstudio, tried jdk 1.7/1.8 same result)

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
//initialize StreamResult with File object to save to file
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(doc);
transformer.transform(source, result);

// Output to console for testing
StreamResult consoleResult = new StreamResult(System.out);
transformer.transform(source, consoleResult); // this give all data to as System.Out as correct every line

xmlString = result.getWriter().toString();
Log.v("XML OUTPUT  xmlString", xmlString.toString()); // but this gives only part of xml like broken from half part...

Aucun commentaire:

Enregistrer un commentaire