XML Output - two classes, different output. Cdata not showing
I am trying to develop a java class to export data into an xml file. Eventually, I plan to hook it to the iteration of a view Object, and export database data into the xml file. Since the data can have many formats, I am trying to export it into a CData element.
I have two projects open in Jdeveloper. One a sample where I developed the xml file, then an ADF model project. I put the class in the same package as the application module. (eventually I hope to have this work from a button on a form).
The output of the XML file should look like this:
<?xml version="1.0" encoding="UTF-8"?>
-<lesson><name>Jdev</name><description>Learn Jdev!</description>
-<card>
<frontside>frontside data</frontside>
-<backside>
*<![CDATA[cdatatest dfadf adfadfadfa adfadsfadf adsfadfadfsadsf adfadfadf]]>*
*</backside>*
</card>
</lesson>
The problem is, the output from the java class in the application module package does NOT produce the CDATA section.
It produces
*<backside>cdatatest dfadf adfadfadfa adfadsfadf adsfadfadfsadsf adfadfadf</backside>*
The code is EXACTLY the same. I checked each project properties to see if there were different libraries (the app module project had a bunch, none for the other).
Stumped in NJ. Would appreciate any help! Thanks
Stuart
Here is my code:
public void WriteDBDataToXML(){
try {
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
// root elements
Document doc = docBuilder.newDocument();
Element rootElement = doc.createElement("lesson");
doc.appendChild(rootElement);
// name elements
Element name = doc.createElement("name");
name.appendChild(doc.createTextNode("Jdev"));
rootElement.appendChild(name);
// description elements
Element description = doc.createElement("description");
description.appendChild(doc.createTextNode("Learn Jdev!"));
rootElement.appendChild(description);
Element card = doc.createElement("card");
rootElement.appendChild(card);
Element frontside = doc.createElement("frontside");
frontside.appendChild(doc.createTextNode("frontside data"));
card.appendChild(frontside);
Element backside = doc.createElement("backside");
//backside.appendChild(doc.createTextNode("backside data"));
card.appendChild(backside);
// this is test for cdata and comments and text...
CDATASection cdataNode = doc.createCDATASection("cdatatest dfadf adfadfadfa adfadsfadf adsfadfadfsadsf adfadfadf");
backside.appendChild(cdataNode);
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("C:\\temp\\works.xml"));
transformer.transform(source, result);
} catch (ParserConfigurationException pce) {
pce.printStackTrace();
} catch (TransformerException tfe) {
tfe.printStackTrace();
}
Edited by: Stuart on May 14, 2012 6:59 PM
Edited by: Stuart on May 14, 2012 6:59 PM
Edited by: Stuart on May 14, 2012 7:05 PM