I want to insert a line feed into an XML document, serialize it to a file,
and then parse it to a DOM document for use in an XSL transform (applying a
sytlesheet). Parsing always throws the following exception.
org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0x10) was
found in the element content of the document.
I have a feeling I'm inserting the wrong character for what I want. Does
anyone have a suggestion? Using "\n", rather than "\u0010", doesn't cause
the exception, but it doesn't get me the desired line feed when I transform
the XML to HTML using an XSL stylesheet.
Test code:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element test = doc.createElement("Test");
test.appendChild(doc.createTextNode("before"));
test.appendChild(doc.createTextNode("\u0010"));
test.appendChild(doc.createTextNode("after"));
doc.appendChild(test);
FileOutputStream fos = new FileOutputStream("C:/myoutput.xml");
Transformer t = transFact.newTransformer(); // identity transform // not
necessary t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); Node
node = doc.getDocumentElement(); DOMSource source = new DOMSource(node);
StreamResult result = new StreamResult(fos); t.transform(source, result);
fos.close(); db.parse(new File("C:/myoutput.xml"));
_________________________________________________________________
FREE pop-up blocking with the new MSN Toolbar ? get it now!
http://toolbar.msn.com/go/onm00200415ave/direct/01/