The XML Helper object is part of Bizagi's business rules API, and it provides data access for your processes when working with XML-structured information, as described at XML Helper object.
This section illustrates an example on how to use one of the methods featured by this object, the transformXmlAsString method, which is oriented to applying a XSL transformation file directly to information you have either obtained from Bizagi's data model, or information you will update into Bizagi's data model.
In the following sample process, assume we have a Parameter entity called Vendor.
Such entity has the following records:
When wanting to fetch these records while formatting under a different structure that the default XML presented by Bizagi, you may rely on a transformation file and do this by using the CEntityXmlHelper.transformXmlAsString method.
In order to work with transformation files, you should create a definition of an XSD schema having the expected XML structure for a given entity.
Create a schema definition in Bizagi Studio, and similarly register in that same option, the given XLS transformation file created for that entity:
For more information about predefining schemas, refer to Bizagi's data model XML schemas.
Now, for this entity's schema and for this example, we will use the following transformation file:
Which exactly contains:
<?xml version="1.0" encoding="utf-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"><xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" /><xsl:template match="/BizAgiWSResponse/Entities"><body><html><h1>Vendors</h1><table><tr><th>Code</th><th>Name</th></tr><xsl:for-each select = "Vendor"><tr><xsl:for-each select = "Code"><td><xsl:value-of select = "."/></td></xsl:for-each><xsl:for-each select = "Name"><td><xsl:value-of select = "."/></td></xsl:for-each></tr></xsl:for-each></table></html></body></xsl:template></xsl:stylesheet>
Therefore and to easily manage the transformation in Bizagi, create it as a .xsl file, so that you register and upload it through the same Bizagi Studio options:
Click on Add to register the transformation and input details (most importantly consider the Name you give it so that you can reference it from business rules):
Browse the transformation file by clicking on Select file.. and locating the file:
Once uploaded, click OK. You may verify that the transformation file is listed.
Now in order to handle information in XML-based use the CEntityXmlHelper.transformXmlAsString method inside of an expression box, in a Bizagi business rule:
The overall expression shown in the image above is coded with the following:
var vendor_info = '<?xml version="1.0" encoding="UTF-8"?><BizAgiWSResponse><Entities><Vendor key="1"><Code>V001</Code>'
+ '<Name>IBM</Name><VType>A</VType></Vendor><Vendor key="3"><Code>V003</Code><Name>Apple</Name><VType>A</VType></Vendor>'
+ '<Vendor key="4"><Code>V004</Code><Name>Microsoft</Name><VType>A</VType></Vendor></Entities></BizAgiWSResponse>';
var vendor_transformation = CHelper.getXSL("Vendor", "Vendor_HTML");
var vendor_result = CEntityXmlHelper.transformXmlAsString(vendor_info, vendor_transformation);
Notice that the incoming records from the Vendor entity are hard-coded for this example (vendor_info) but that information complies to what invoking the CEntityXmlHelper.getEntitiesAsString method fetches.
For more information about the getEntitiesAsString method, refer to Querying XML-based information in entities.
Notice in the example above, that though two other methods are being used optionally (both CHelper.trace and CHelper.getXSL) these will often can be used together with CEntityXmlHelper.transformXmlAsString for other purposes:
•CHelper.trace: Allows you to print out custom traces of values and responses in the execution of the rules.
The image below shows what the sample expression prints out:
For more information about the use of this tracing option, refer to Validating business rules.
•CHelper.getXSL: Allows you to obtain a predefined transformation file that you registered for any entity, as configured in Bizagi Studio.
The image below shows the registered transformation file for the Vendor entity, explicitly named as Vendor_HTML (as referenced in the sample expression):
For more information about predefining schemas and transformations, refer to Bizagi's data model XML schemas.