public static void writeCollection(BusinessObject businessObject, File parentFolder, int depth){
        String businessObjectName = businessObject.getName();
        String businessObjectType = businessObject.getBusinessObjectType();
        parentFolder.mkdirs();
        File childFolder = null;
        try{
            childFolder = new File(parentFolder, businessObjectName);
        } catch (NullPointerException npe){
            npe.printStackTrace();
        }
        File xmlFile = new File(parentFolder, businessObjectName+".xml");
        try {
            Writer writer = new FileWriter(xmlFile);

            // Write the header with correct XSL-File, DTD-File and DTD-Root-Element
            writer.write(getXmlHeader(businessObject, depth));

            // get the object's properties
            Properties collectionProperties = businessObject.getOutputProperties();

            writer.write(writeNode(collectionProperties, 0));

            if(businessObject instanceof BusinessCollection){
                BusinessCollection businessCollection = (BusinessCollection)businessObject;
                writeChildren(writer, businessCollection, 0);

                if(businessCollection.getCurrentObject()!=null){
                    writer.write("  <CurrentObject>" + businessCollection.getCurrentObject().getName() + "</CurrentObject>\n");
                }
            }

            writer.write("</"+businessObjectType+">\n");

            writer.flush();
            writer.close();
//			setSaved(true);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(BusinessCollection.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(BusinessCollection.class.getName()).log(Level.SEVERE, null, ex);
        }

        if(businessObject instanceof BusinessCollection){
            BusinessCollection businessCollection = (BusinessCollection)businessObject;
            if (businessCollection instanceof ChildrenNeedSeparateFile) {
                for(Object object : businessCollection.getBusinessObjects()) {
                    if(object instanceof BusinessObject) {
                        BusinessObject childObject = (BusinessObject) object;
                        writeCollection(childObject, childFolder, depth + 1);
                    }
                }
            }
        }
    }