### Question:
XmlPayloadIO implements IPayloadIO<Document> { @Override public byte[] marshall(Document data) throws Exception { Transformer transformer = TransformerFactory.newInstance().newTransformer(); StreamResult result = new StreamResult(new StringWriter()); DOMSource source = new DOMSource(data); transformer.transform(source, result); String xml = result.getWriter().toString(); String enc = data.getXmlEncoding(); if (enc == null) { enc = "UTF8"; } return xml.getBytes(enc); }  @Override Document unmarshall(InputStream input); @Override Document unmarshall(byte[] input); @Override byte[] marshall(Document data);  }### Answer:
@Test public void testMarshall_Simple() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder builder = dbf.newDocumentBuilder(); Document document = builder.newDocument(); Element bookElem = document.createElementNS("urn:ns1", "book"); document.appendChild(bookElem); Element authorElem = document.createElementNS("urn:ns1", "author"); Element titleElem = document.createElementNS("urn:ns1", "title"); Element genreElem = document.createElementNS("urn:ns1", "genre"); authorElem.setTextContent("Gambardella, Matthew"); titleElem.setTextContent("title"); genreElem.setTextContent("Computer"); bookElem.appendChild(authorElem); bookElem.appendChild(titleElem); bookElem.appendChild(genreElem); XmlPayloadIO io = new XmlPayloadIO(); byte[] xmlBytes = io.marshall(document); String xml = new String(xmlBytes); String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>" + "<book xmlns=\"urn:ns1\">" + "<author>Gambardella, Matthew</author>" + "<title>title</title>" + "<genre>Computer</genre>" + "</book>"; Assert.assertEquals(expected, xml); }