Skip to main content

Why XMLStreamWriter doesn't escape lf, cr and tab characters?

No replies
acc15
Offline
Joined: 2008-11-15
Points: 0

StAX:

XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = outputFactory.createXMLStreamWriter(new FileOutputStream("test.xml"));

writer.writeStartDocument("1.0");
writer.writeStartElement("openElement1");
writer.writeAttribute("attribute1","test&va\tlue\n");
writer.writeEndElement();
writer.writeEndDocument();
writer.close();

this will generate an simple XML without escaping of &#D, &#A, &#9 characters. Then, when i try to parse this document using SAX parser this characters will be simply replaced by single space (' ') = data lost