String dtd = extractDtd(outputXmlFileName);
return toXML(bean, dtd, outputXmlFileName);
}
public static boolean toXML(Object bean, String dtdFileName, String outputXmlFileName) throws Exception {
MyJOXBeanOutputStream joxOut = null;
DTD dtd = null;
FileOutputStream fileOut = new FileOutputStream(outputXmlFileName);
if (dtdFileName != null) {
FileReader reader = new FileReader(dtdFileName);
DTDParser dtdParser = new DTDParser(reader);
dtd = dtdParser.parse();
reader.close();
joxOut = new MyJOXBeanOutputStream(dtd, fileOut);
} else {
//JOXBeanOutputStream joxOut = new JOXBeanOutputStream(dtd, fileOut);
//ByteArrayOutputStream xmlData = new ByteArrayOutputStream();
joxOut = new MyJOXBeanOutputStream(fileOut);
}
try {
joxOut.writeObject(beanName(bean), bean, doctypeDeclaration);
//IndentingParser.writeIdented(outputXmlFileName);
} catch (IOException exc) {
exc.printStackTrace();
return false; //null;
} finally {
try {
//xmlData.close();
fileOut.close();
joxOut.close();
} catch (Exception e) {
e.printStackTrace();
}
}