Hello,
I'm trying to read in a text file and convert it to XML. I want to add some tags early, read in the file, and then be able to add tags afterwards. I want to keep all the white space and line breaks in text from the file though, so I'm trying to use a CDATA tag to do this. My problem is my program compiles, but when I run the program, I get a SAX Parsing exception that reads:
org.xml.sax.SAXParseException: EOF while parsing <![CDATA[ section. [/b]
Like I said, I do need to keep all the other delimiters, but I don't need the EOF. Can I tell the CDATA tag to somehow ignore the EOF marker, or do I have to somehow remove it from my text file?
Thanks!
My xmlConverter code (very very basic):
public void xmlConverter(String filename){
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
try {
File f = new File(filename);
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse(f);
// Get the first <slide> element in the DOM
NodeList list = document.getElementsByTagName("DriverSheet");
Node node = list.item(0);
// Use a Transformer for output
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(node);
StreamResult result = new StreamResult("XMLFILES/"+idString+".xml");
transformer.transform(source, result);
} catch (TransformerConfigurationException tce) {
// Error generated by the parser
System.out.println ("\n** Transformer Factory error");
System.out.println(" " + tce.getMessage() );
// Use the contained exception, if any
Throwable x = tce;
if (tce.getException() != null)
x = tce.getException();
x.printStackTrace();
} catch (TransformerException te) {
// Error generated by the parser
System.out.println ("\n** Transformation error");
System.out.println(" " + te.getMessage() );
// Use the contained exception, if any
Throwable x = te;
if (te.getException() != null)
x = te.getException();
x.printStackTrace();
} catch (SAXException sxe) {
// Error generated by this application
// (or a parser-initialization error)
Exception x = sxe;
if (sxe.getException() != null)
x = sxe.getException();
x.printStackTrace();
} catch (ParserConfigurationException pce) {
// Parser with specified options can't be built
pce.printStackTrace();
} catch (IOException ioe) {
// I/O error
ioe.printStackTrace();
}
} //end XMLConverter