// this is an object representation of a NeXML document
Document nexDoc = DocumentFactory.safeCreateDocument();
// the converter populates the NeXML document with the contents of the treebase study
NexmlDocumentWriter ndc = new NexmlDocumentWriter(tbStudy,getTaxonLabelHome(),nexDoc);
ndc.fromTreeBaseToXml(tbStudy); // here is where the conversion happens
attachAnalysisMetadata(analyzedDataForData, tbStudy, nexDoc);
// attach analysis step metadata to matrices
for ( Matrix<?> nexMatrix : nexDoc.getMatrices() ) {