related codes
String newContent = ":\r\n" + "1. \r\n" + "";
DocumentBuilder builer = null;
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setIgnoringElementContentWhitespace(true);
try {
builer = documentBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document document = builer.newDocument();
Element rootElement = document.createElement("xml");
document.appendChild(rootElement);
Element element = document.createElement("Content");
CDATASection cDATASection = document.createCDATASection(newContent); //
element.appendChild(cDATASection);
rootElement.appendChild(element);
TransformerFactory fransformerFactory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = fransformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
StringWriter stringWriter = new StringWriter();
try {
transformer.transform(new DOMSource(document), new StreamResult(stringWriter));
} catch (TransformerException e) {
e.printStackTrace();
}
String retval = stringWriter.toString();
System.out.println(retval);
what result do you expect? What is the error message actually seen?
but the output is
xml version= "1.0" encoding= "UTF-8" standalone= "no"? > < xml > < Content >
- introduction to the Ode of Joy
Please select] < / Content > < / xml >
the result I want to use is
xml version= "1.0" encoding= "UTF-8" standalone= "no"? > < xml > < Content >
- introduction to the Ode of Joy
Please select] < / Content > < / xml >