StringTools.append(annotationBeginning, Character.valueOf('>'),
Character.valueOf('\n'), annotation.getNonRDFannotation(),
whiteSpaces, "</annotation>", Character.valueOf('\n'));
DOMConverter converter = new DOMConverter();
String annotationString = annotationBeginning.toString()
.replaceAll("&", "&");
// here indent gets lost.
Document domDocument = null;
boolean domConversionDone = false;
try {
domDocument = JAXPFacade.getInstance().create(
new BufferedReader(new StringReader(annotationString)), allNamespacesDefined);
domConversionDone = true;
} catch (SAXException e) {
e.printStackTrace();
// TODO : log error or send SBMLException
logger.warn("Cannot parse the following XML\n@" + annotationString + "@");
logger.warn("NonRDFannotation =\n@" + annotation.getNonRDFannotation() + "@");
// trying to read the XML without namespace awareness as the XML can be wrong and we still want to
// write it back as it is.
if (allNamespacesDefined) {
try {
domDocument = JAXPFacade.getInstance().create(
new BufferedReader(new StringReader(annotationString)), false);
domConversionDone = true;
} catch (SAXException e2) {
e.printStackTrace();
// TODO : log error or send SBMLException
}
}
} finally {
if (domConversionDone) {
converter.writeFragment(domDocument.getFirstChild()
.getChildNodes(), writer);
}
}
} else {
writer.writeCharacters("\n");