XMLEventWriter write without escaping

plmmlp

New Member
I wanted to use StringEscapeUtils.escapeXML(...) of apache while writing my xml, since I am dealing with special characters like ?.How can I disable the default escaping done by XMLEventWriter? It escapes again ampersands from the apache escaped text. e.g. from æ to &#230;XMLStreamWriter writeCharacters without escapingsuggests to disable propety escapeCharacters; however I could not find such property for XMLOutputFactory. Am I missing something?Any help is much appreciated.\[code\]public static void main(String[] args) throws XMLStreamException, FactoryConfigurationError { String inXml = "<?xml version='1.0' encoding='utf-8'?><test><begin/><specialchar>pre & æ post</specialchar><end/></test>"; XMLEventReader reader = XMLInputFactory.newInstance().createXMLEventReader(new StringReader(inXml)); XMLEventFactory factory = XMLEventFactory.newInstance(); XMLEventWriter writer = XMLOutputFactory.newInstance().createXMLEventWriter(System.out); while (reader.hasNext()) { XMLEvent event = (XMLEvent) reader.next(); if(event.isCharacters()){ writer.add(factory.createCharacters(StringEscapeUtils.escapeXml(event.asCharacters().getData()))); }else{ writer.add(event); } } writer.flush();}\[/code\]
 
Back
Top