Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse
(new InputSource(new StringReader(SIMPLE_XML)));
assertNotNull(doc);
ObjectMapper mapper = new ObjectMapper();
// need to strip xml declaration, if any
String outputRaw = mapper.writeValueAsString(doc);
// And re-parse as String, since JSON has quotes...
String output = mapper.readValue(outputRaw, String.class);
/* ... and finally, normalize to (close to) canonical XML
* output (single vs double quotes, xml declaration etc)
*/