public static Element getMonomerElement ( Monomer monomer ) throws MonomerException { Element element = new Element ( MONOMER_ELEMENT ) ; if ( null != monomer . getAlternateId ( ) ) { Element e = new Element ( MONOMER_ID_ELEMENT ) ; e . setText ( monomer . getAlternateId ( ) ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getCanSMILES ( ) ) { Element e = new Element ( MONOMER_SMILES_ELEMENT ) ; e . setText ( monomer . getCanSMILES ( ) ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getMolfile ( ) ) { Element e = new Element ( MONOMER_MOL_FILE_ELEMENT ) ; String encodedMolfile = null ; try { encodedMolfile = MolfileEncoder . encode ( monomer . getMolfile ( ) ) ; } catch ( EncoderException ex ) { throw new MonomerException ( "Invalid monomer molfile" ) ; } // CDATA cdata = new CDATA(monomer.getMolfile()); // e.setContent(cdata); e . setText ( encodedMolfile ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getMonomerType ( ) ) { Element e = new Element ( MONOMER_TYPE_ELEMENT ) ; e . setText ( monomer . getMonomerType ( ) ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getPolymerType ( ) ) { Element e = new Element ( POLYMER_TYPE_ELEMENT ) ; e . setText ( monomer . getPolymerType ( ) ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getNaturalAnalog ( ) ) { Element e = new Element ( NATURAL_ANALOG_ELEMENT ) ; e . setText ( monomer . getNaturalAnalog ( ) ) ; element . getChildren ( ) . add ( e ) ; } if ( null != monomer . getName ( ) ) { Element e = new Element ( MONOMER_NAME_ELEMENT ) ; e . setText ( monomer . getName ( ) ) ; element . getChildren ( ) . add ( e ) ; } List < Attachment > l = monomer . getAttachmentList ( ) ; if ( null != l && l . size ( ) > 0 ) { Element attachments = new Element ( ATTACHEMENTS_ELEMENT ) ; for ( int i = 0 ; i < l . size ( ) ; i ++ ) { Attachment att = l . get ( i ) ; Element attachment = getAttachementElement ( att ) ; attachments . getChildren ( ) . add ( attachment ) ; } element . getChildren ( ) . add ( attachments ) ; } return element ; }
This method converts Monomer to MONOMER XML element