EvaluateXML Overview

The service "EvaluateXML" is used to translate XML into data nodes as children of the WorkData node to be used in the process later.

Example: "<Container><Test1>123</Test1><Test2>abc</Test2></Container>" will create the nodes "WorkData/Container/test1" and "WorkData/Container/Test1" so they can be referenced by XSLT later in the process.

This is useful if you want to create an XML structure that cannot be created in a similar service, such as Evaluate. For example, WorkData/Variable could not be created with Evaluate. Instead, it would have to be WorkData/Evaluate/Variable. With the EvaluateXML the desired structure is possible.

We can also control the existence of node based on certain conditions. If you want to create an eval in an Evaluate service, once an eval is defined, it exists and it cannot be un-created depending on a blank value. With an EvaluateXml, the xml node could be wrapped in an XSLT “If”, “Choose”, or “For-Each”. With these XSLT functions, if the correct conditions are met, the XML node will exist.

EvaluateXml gives developers lots of control over the nodes created and works very well with XSLT functions. Many complex functions could be used at once to create a desired XML structure without the constraints of EASYProcess build XML.

Odd XML Structures

One of the benefits of an EvaluateXml service is the amount of control over the XML structure it gives the developer. Below are some examples of the EvaluateXml services used to for this reason.

API Output

In the API contract definition, it was required that the CartId of the current user be output in the format: WorkData/CartId. For this an Evaluate service could not be used since it would have to  output WorkData/Evaluate/CartId.

Here was the existing output for the process when an Evaluate services was used:

Here is the output after it was converted to an EvaluateXml service. Notice since it has the developer defined XML, it is not organized nicely in the service and is less readable. However, two nodes were defined beneath the WorkData node in this EvaluateXml: ResponseInfo and CartId.

 In the screenshot the Xml nodes which mark the beginning of and the end of the developer-entered xml are highlighted.

Use with XSLT

EvaluateXml is a great service to use with complex XSLT functions. Below are examples of the services used for this reason.

Using For-Each to Create Nodes

Sometimes an existing node set will need to be referenced and will be used to determine the output. For example, for each item passed in, to this pricing process, an item node must be returned in the output with the item’s price and other info. If an item cannot be found or priced, each item must return in the output with its own node and information about why it failed.

With this requirement, it is easy to see why a developer would want to say “for each item passed in, output an xml node”. This can be done to dynamically build the Xml of the output depending on the input using Evaluate Xml and the XSLT For-Each function.

Here is that EvaluateXml. The nodes dynamically created based on the input are circled. This is the output node when items fail. Each node (named either NotInUserCatalog or NotFound) returned corresponds to an item node passed (WorkData/Item) in which was given an attribute (NotInUserCatalog and NotFound) to be used to identify the failed items.

Using XSLT Copy-Of to Create Nodes

Using the XSLT Copy-Of function, it copies all the existing XML at the target node. The asterisk is then used to copy all children nodes.

In this example, we have a pricing process. The input to the process is given in WorkData/Item. Then each item is taken and given a “Valid” attribute with either “True” or “False”. This is used later in this output EvaluateXml. There is a for-each which will iterate through all the item nodes that are given as input. However, it will only iterate through the ones with their “Valid” attribute set to “True”. This way, it will only iterate through the items that have information to return (invalid items are not returned here).

After targeting the correct nodes to iterate through, two variables are defined (ItemNumber and Quantity). These are the two pieces of information needed to differentiate between items in the input.

There is an existing RunQuery named “GetItem” which finds all the item info of the items requested by the input of the process.

With the two variables, a copy-of xslt variable is used to target the correct result from the “GetItem” service (the one from the iteration of the input we are on) and copy all the XML returned by the “GetItem” service to the EvaluateXml. The EvalauteXml service is wrapping all this information in an “Item” node, so each item will output an Item node just the same way it was passed in.

Notice that because we are in a For-Each loop, the reference to the GetItem service must exit the for each loop path to reference the correct node. It does this by placing a “/” before the WorkData.

The asterisk selects all child nodes. So this will select all the child nodes of the GetItem service. This will be attributes of the item like ItemNumber, Quantity, and Price.

The EvaluateXml created an output node named “Item”. See below as the Item node now has all the attributes from the GetItem service.