1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| private String miseEnFormeXml(String xmlString) {
try {
SAXBuilder builder = new SAXBuilder();
Document document = builder.build(toInputStream(xmlString));
xmlString = documentToString(document);
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return xmlString;
}
private static InputStream toInputStream(String string) {
return new ByteArrayInputStream(string.getBytes());
}
private static String documentToString(Document document) throws IOException {
XMLOutputter outp = new XMLOutputter();
outp.setFormat(Format.getPrettyFormat().setIndent(" "));
StringWriter sw = new StringWriter();
outp.output(document.getContent(), sw);
return sw.getBuffer().toString();
} |