Geeks With Blogs
Evan Koch Musings on BizTalk Server and SQL Server

One of the components provided with BizTalk Server 2004 and 2006 is the Business Rules Engine.  It's touted as one of the big benefits of going with BizTalk as a business user can administer the rules and affect changes without needing to understand the intricacies of BizTalk.  The BRE can also be used outside of BizTalk which is something that might merit investigation later.  For now, I'll cover three methods of manipulating XML data I often use.  I'll also take a moment to mention that this post isn't intended as an introduction to the BRE or how/why to use it; for the purposes of this post, some knowledge of the BRE is assumed.  In this scenario we'll pass in a xml that contains a few elements of loan data and modifying another xml that contains information for generating loan documents.  As with most other things in programming, there's many ways of accomplishing something - I'm just presenting the ways that work for me.

 First scenario is setting the value of an existing node.  In the XML document we're manipulating, we have the following:

Many states (or sometimes specific cities/counties) dictate that the loan documents be printed on letter sized paper so we'll set up a rule to handle that.

After testing the rule with our two XMLs, if the property state does indeed happen to match one of the criteria above, the action will be performed and the value of the PaperSize node will be updated to Letter.  I use vocabularies heavily in my rules as it makes everything infinitely more readable.  It's easier to understand PaperSize than /MortgageDocuments/PaperSize.

The next scenario would be creating a node and specifying the value.  In BizTalk 2006 Microsoft supplied the Microsoft.RuleEngine.XMLHelper class which is extremely useful.  Prior to this one would have to write custom code to add elements to the XML.  Our example is based on the Redemption Period that's specific to South Dakota lending laws - we only need to specify the node and its value if the property state is South Dakota.

After the rule has been executed, the XML will look like this:

It's worthwhile to pay attention to the function prototype for AddNodeWithValue:

public static void AddNodeWithValue(Microsoft.RuleEngine.TypedXmlDocument document, string xpath, string nodeName, object nodeValue)

In the above example, I've passed in a particular spot within the XML  and the Xpath expression I've used is the current location (the period) within the document.  The Xpath parameter plays an important role in the next scenario.

The third scenario relates to creating a repeating node set within the XML.  We'll specify different mortgage documents and security instruments based on the loan - some are based on loan type, property state, property type, etc.  We'll assume an empty MortgageDocuments node in the XML as our starting point.

I've provided the desired end result below.  The tricky part of this is that within the policy it's feasible for us to create multiple MortgageDocument nodes within the MortgageDocuments node so we have to specify in which instance of the node to add the nodes.  Since we don't know how many MortgageDocument nodes we'll have, it's easier to use relative positioning in this case.  To that end, we specify [position()=last()) as part of our XPath expression.  This will ensure that the nodes added in the Actions are created within the most recent MortgageDocument node.

In a more realistic situation, this would allow us to define all the mortgage documents required for Georgia:

So these are just a few ways one can set values within the BRE.  Some of the other techniques I've used are to call external functions or perform database lookups to provide the node values.

Source code for this example can be found here.

Posted on Friday, August 10, 2007 4:33 PM | Back to top

Comments on this post: Manipulating XML in the Business Rules Engine

# re: Manipulating XML in the Business Rules Engine
Requesting Gravatar...
thans best regards
Left by can on Nov 20, 2007 7:15 AM

# re: Manipulating XML in the Business Rules Engine
Requesting Gravatar...
thanks a lot
Left by sharmishtha on Jan 27, 2009 8:44 AM

# re: Manipulating XML in the Business Rules Engine
Requesting Gravatar...
Hi Evan,

Realy interesting article, even if ist matured.
This is realy what I need for my project.
Tough, the .NET code si missing in the Zipfile (cs class)
Do you still have it?

Kind regards,

Left by Remco on May 19, 2013 8:04 PM

Your comment:
 (will show your gravatar)

Copyright © Evan Koch | Powered by: