Hello!
I want to store some fragments of an XML file in separate files. It seems, there is no way to do it in a straight way: Reading the chunks fails.
I always get the Exception "javax.xml.transform.TransformerException: org.xml.sax.SAXParseException: The markup in the document following the root element must be well-formed."
It only works when there is only ONE 'root' element (which is not the root element in the normal sense).
I understand that XML with multiple 'roots' is not well-formed, but it should be treated as a chunk.
Please, before suggesting some work-around-solutions, tell me: Are XML chunks valid at all?
And IF so, can they be read out using standard JDK6 API?
Test code:
String testChunk1 = "<e1>text</e1>";
String testChunk2 = "<e1>text</e1><e2>text</e2>";
// the following doesn't work with 'testChunk2'
StringReader sr = new StringReader(testChunk1);
StringWriter sw = new StringWriter();
TransformerFactory.newInstance().newTransformer().transform(
new StreamSource(sr), new StreamResult(sw));
System.out.println(sw.toString());