Omit Comments Does not Work 2004-01-16 - By Thomas
Hello!
I have two questions:
(1) I want to preserve comments in the following lines, but it does not work: comments are still removed.
memoryxml.reset(); try { InputSource input = new InputSource(memoryxml); input.setEncoding("utf-8"); input.setByteStream(memoryxml);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false);
DocumentBuilder parser = factory.newDocumentBuilder();
Document document = parser.parse(input);
OutputFormat format = new OutputFormat(document, "utf-8", true); format.setLineWidth(100); format.setIndent(4); format.setOmitComments(false); format.setOmitXMLDeclaration(false); format.setOmitDocumentType(false); format.setPreserveSpace(false);
StringWriter sw = new StringWriter();
XMLSerializer serializer = new XMLSerializer(sw, format);
try { serializer.asDOMSerializer();
serializer.serialize(document.getDocumentElement()); } catch (Exception ex) { logger.error("Serializing Exception " + ex.getMessage()); } return sw.toString();
} catch (SAXException sex) { logger.error("SAXException: " + sex.getMessage()); } catch (IOException iox) { logger.error("IOException: " + iox.getMessage()); } catch (ParserConfigurationException pcex) { logger.error("ParserConfigException:" + pcex.getMessage()); }
(2) How can I ensure that the Xerces parser is really used and not Crimson (JDK 1.4) ? Can I dynamically load the Xerces parser somehow?
Thanks for your info!
Kind regards, Tommy
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|