Skip to main content

How to tranform a xml file into a Imixs XML EntityCollection

  1 post   Feedicon  
Replies: 0 - Last Post: August 02, 2011 17:59
by: Ralph
showing 1 - 1 of 1
Posted: August 02, 2011 17:59 by Ralph
The following code example shows how you can transform a xml file with a xsl template directly into a Imixs XML EntityCollection object. Thus a object can be used to post data via the RESTfull service interface.


private EntityCollection transform(Document xmldoc) throws TransformerException {
	DOMSource domSource =null;
	domSource = new DOMSource(xmldoc);
	String sXSLPath="C:" + File.separator
	+ "imixs.xsl";
	System.out.println("[ImixsWorkflow] ***** XSL Sourcefile:"+sXSLPath);
	// get the xsl template
	StreamSource stylesource = new StreamSource(sXSLPath);
	// create a transformer factory
	TransformerFactory factory = TransformerFactory.newInstance();
	Transformer transformer = factory.newTransformer(stylesource);
	// create a ByteArray Output Stream
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	transformer.transform(domSource, new StreamResult(outputStream));
	System.out.println("[ImixsWorkflow] ***** Unmarschalling started...");
	// now unmarshal the result outputStream int a XML EntityCollection..
    JAXBContext context;
	try {
		context = JAXBContext.newInstance(EntityCollection.class);
        Unmarshaller u = context.createUnmarshaller();
        EntityCollection ecol = (EntityCollection) u.unmarshal(new ByteArrayInputStream(outputStream.toByteArray()));
    	System.out.println("[ImixsWorkflow] ***** Unmarshal Imixs xml successfull!");
        return ecol;
	} catch (JAXBException e) {
		// Unable to unmarshal!!
		System.out.println("[ImixsWorkflow] ***** Unable to unmarshal Imixs xml result: " + e.getMessage());
		e.printStackTrace();
		return new EntityCollection();
	}

}
Replies: 0 - Last Post: August 02, 2011 17:59
by: Ralph
 
 
Close
loading
Please Confirm
Close