StringSource extends StreamSource { public StringSource(String content) { Assert.notNull(content, "'content' must not be null"); this.content = content; } StringSource(String content); @Override Reader getReader(); @Override void setInputStream(InputStream inputStream); @Override InputStream getInputStream(); @Override void setReader(Reader reader); @Override String toString();  }
@Test public void testStringSource() throws TransformerException { Transformer transformer = TransformerFactoryUtils.newInstance().newTransformer(); String content = "<prefix:content xmlns:prefix='namespace'/>"; DOMResult result = new DOMResult(); transformer.transform(new StringSource(content), result); Element rootElement = (Element) result.getNode().getFirstChild(); Assert.assertEquals("Invalid local name", "content", rootElement.getLocalName()); Assert.assertEquals("Invalid prefix", "prefix", rootElement.getPrefix()); Assert.assertEquals("Invalid namespace", "namespace", rootElement.getNamespaceURI()); }