You are here

You are here

Document Generation via XML Merge

SpringCM's XML merge engine is exposed in Advanced Workflow, Document Builder, and the web services API.  The same merge templates can be used by all three methods.  The API version exposes a number of datasources to the merge including document and folder metadata, an existing XML file in SpringCM or a custom XML string. 

Executing a merge via the API is an asynchronous process.  The merge is initiated via the DocumentXMLMerge method call which returns a token that can be used subsequently with the DocumentXMLMergeStatus method to check the status of the merge process.  When the merge completes successfully the SCMXMLMergeResult object returned will expose the document Id of the newly generated document.

Do not confuse the  the DocumentXMLMerge method, which creates a new document based on an XML datasource and merge template with the DocumentMerge method, which combines documents together.

Vertical Tabs

c#
// Here we could do some logic to select a template, but it is hard coded for now
SCMDocument mergeTemplateDocument = springCMService.DocumentGetById(token,"<Source document Id retrieved by other method calls>",false);
 
//Here we can set an existing SpringCM document or folder as the datasource
//and we would use its metadata as the merge document source
//The options are:
//      --SCMXMLSourceType.String and populate SCMXMLSourceType.String with custom xml
//      --SCMXLLSourcetype.Document and populate with SCMXMLSourceType.Object with SCMDocument who's metadata to merge
//      --SCMXLLSourcetype.DocumentContent and populate with SCMXMLSourceType.Object with SCMDocument or an XML file in SpringCM
//      --SCMXLLSourcetype.Folder and populate with SCMXMLSourceType.Object with SCMFolder who's metadata to merge
//In this example, we use a custom XML string
SCMXMLDataSource xmlDataSource = new SCMXMLDataSource();
xmlDataSource.SourceType = SCMXMLSourceType.String;
 
//At this point we could get our XML from anywhere, a back end system most likely
string xml = "<Data><Data1>I am data 1 value</Data1><Data2>I am data2 value</Data2></Data>";
xmlDataSource.String = xml;
 
//Here we could do some logic to determine the target folder for newly
//generated document, but its hard coded for now
SCMFolder destinationFolder = springCMService.FolderGetById(token, "<Folder Id is retrieved by other method calls>",false);
 
String documentName = "New merge document.docx";
 
//Kick off the merge
String requestToken = springCMService.DocumentXMLMerge(token, mergeTemplateDocument, xmlDataSource,
													   destinationFolder, documentName);
Console.WriteLine("Status token is: " + requestToken);
 
//Optionally monitor and report status
SCMXMLMergeResult mergeResult = springCMService.DocumentXMLMergeStatus(token, requestToken);
while (mergeResult.Status == SCMQueueStatus.Processing || mergeResult.Status == SCMQueueStatus.Waiting)
{
	Thread.Sleep(3000);
	mergeResult = springCMService.DocumentXMLMergeStatus(token, requestToken);
}
 
//Check result
if (mergeResult.Status == SCMQueueStatus.Success)
{
	Console.WriteLine("Document created successfully with id:" + mergeResult.DocumentId);
}
 
if (mergeResult.Status == SCMQueueStatus.Failure)
{
	Console.WriteLine("Document creation failed:" + mergeResult.Message);
}
java
// Here we could do some logic to select a template, but it is hard coded for now
SCMDocument mergeTemplateDocument = springCMService.documentGetById(token, "<Source document Id retrieved by other method calls>", false);
 
//Here we can set an existing SpringCM document or folder as the datasource
//and we would use its metadata as the merge document source
//The options are:
//      --SCMXMLSourceType.String and populate SCMXMLSourceType.String with custom xml
//      --SCMXLLSourcetype.Document and populate with SCMXMLSourceType.Object with SCMDocument who's metadata to merge
//      --SCMXLLSourcetype.DocumentContent and populate with SCMXMLSourceType.Object with SCMDocument or an XML file in SpringCM
//      --SCMXLLSourcetype.Folder and populate with SCMXMLSourceType.Object with SCMFolder who's metadata to merge
//In this example, we use a custom XML string
SCMXMLDataSource xmlDataSource = new SCMXMLDataSource();
xmlDataSource.setSourceType(SCMXMLSourceType.String);
 
//At this point we could get our XML from anywhere, a back end system most likely
String xml = "<Data><Data1>I am data 1 value</Data1><Data2>I am data2 value</Data2></Data>";
xmlDataSource.setString(xml);
 
//Here we could do some logic to determine the target folder for newly
//generated document, but its hard coded for now
SCMFolder destinationFolder = springCMService.folderGetById(token, "<Folder Id retrieved by other method calls>",false);
 
String documentName = "New merge document.docx";
 
//Kick off the merge
String requestToken = springCMService.documentXMLMerge(token, mergeTemplateDocument, xmlDataSource, destinationFolder, documentName);
System.out.println("Status token is: "+requestToken);
 
//Optionally monitor and report status
SCMXMLMergeResult mergeResult = springCMService.documentXMLMergeStatus(token, requestToken);
while(mergeResult.getStatus()==SCMQueueStatus.Processing || mergeResult.getStatus()==SCMQueueStatus.Waiting)
{
	Thread.sleep(3000);
	mergeResult = springCMService.documentXMLMergeStatus(token, requestToken);
}
 
//Check result
if(mergeResult.getStatus()==SCMQueueStatus.Success)
{
	System.out.println("Document created successfully with id:"+mergeResult.getDocumentId());
}
 
if(mergeResult.getStatus()==SCMQueueStatus.Failure)
{
	System.out.println("Document creation failed:"+mergeResult.getMessage());
}