Geeks With Blogs
Broken Rules Jason Hyland throws mud at the BizTalk 2004 Rules Engine & API, and sees which bits stickā€¦

The following is an extract from a thread at msnusers.com/biztalkserverstuff. Charles Young explains with great clarity the subtle differences in the rules engine parsing of facts expressed using XPath Selector and XPath Field combinations (or “facts” and “slots”);

This causes so much confusion.
 
The rules engine works by asserting 'facts' into its working memory.   A 'fact' is some object, and therefore contains fields, commonly called 'slots' in the world of rule engines.   The exception is thrown because the rule engine is attempting to access a slot in a fact in order to evaluate a condition within a rule.   The engine is attempting to do this evaluation because the relevant fact has been asserted.   However, when it looks for the slot, it can't find it.
 
This translates into the world of XML as follows.   When you create a vocabulary definition for a node in your schema, there are two properties that are set.   These are 'XPath Selector' and 'XPath Field'.   Thinks of these as the technical terms that refer to some data item.   The vocabulary definition is mapping these to business-friendly terms defined by the Name and Display Name properties.
 
The XPath Selector is used to define and select a 'fact'.   Vocabulary definitions can refer to a fact, rather than a slot, and in this case the XPath Field property is empty.   However, in your case, there will be an additional XPath expression in the XPath Field property.   This will typically be used to select a descendant node of the fact.   The exception is happening because the 'fact' (the programId element) exists (i.e., the XML Selector addresses at least one programId element - if it addresses more than one programId element, multiple facts will be asserted into memory), but the 'slot' (the id element) does not.
 
If the programId element did not exist, no error would occur.   Very simply, the engine would not be able to assert the programId fact and would therefore realise that it could not evaluate any rule conditions that depends on this fact.   Because the programId element exists, the engine assumes that the id child element exists, and throws an error when it finds it doesn't.
 
One way to deal with this is to edit your XPath Selector so that it only selects programId elements that contain an id element.   XPath support filters, so you could amend your selector as follows (addition shown in bold):
 
"/*[local-name()='SOA_Message' and namespace-uri()='http://schemas.test.com/20050307/SoaMessageSchema']/*[local-name()='products' and namespace-uri()='']/*[local-name()='clients' and namespace-uri()='']/*[local-name()='client' and namespace-uri()='']/*[local-name()='programs' and namespace-uri()='']/*[local-name()='program' and namespace-uri()='']/*[local-name()='programId' and namespace-uri()=''][id]"
 
You might want to further improve on this with the following filter [id = ""].   This would only select programId nodes as facts if they contain an id child element with a non-empty text node.
 
The key to running the rules engine effectively over XML is to understand XPath and the difference between 'facts' and 'slots', and to edit your XPath Selectors and XPath Fields accordingly to meet your needs.

Posted on Monday, June 6, 2005 10:32 AM Rules Engine , Vocabulary | Back to top


Comments on this post: Facts and Slots: XPath Selector and XPath Field

# re: Facts and Slots: XPath Selector and XPath Field
Requesting Gravatar...
Hi,

This article is in problem, your section on further improving the XPath is incorrect, [id = ""] should be [id != ""]. I guess you copied the details from the book Pro BizTalk 2006, Page 291 and then did not test your own advice?? Or am I missing the boat? Since the book is also wrong [FIELD2=""] Should be [FIELD2=!"].

Also what cheeses me off, is the problem when you set a filter in a condition and NOBODY then mentions the bad messup that you then have to create a SET vocabulary with the same filter, which is not a good idea, since you then have mulitiple action vocab names like SetRole (Based on Age), or SetRole (Based on Height) etc.

IF AGE <.....
Set Role =...

So above for the filter, u set it on age, you ALSO need to set it on role, but what if you have this
IF Height<.....
Set Role =...
The role was already filtered on age, so you make a new vocab,

IF Height<.....
Set Role(Height) =...

IF Age<.....
Set Role(Age) =...


So the WORKAROUND is rubbish.
Left by rOMIKO on Feb 26, 2008 8:46 AM

# re: Facts and Slots: XPath Selector and XPath Field
Requesting Gravatar...
Small error above [FIELD2=""] Should be [FIELD2!=""].

So any solutions you guys can think of, on this problem in BRE? We want to handle elements that do not exist and not duplicate word my creating mulitple actions for the same element with different filters?
Left by Romiko on Feb 26, 2008 9:12 AM

# re: Facts and Slots: XPath Selector and XPath Field
Requesting Gravatar...
agree with rOMIKO.
Left by jimmy on Nov 08, 2009 9:01 PM

Your comment:
 (will show your gravatar)


Copyright © Jason Hyland | Powered by: GeeksWithBlogs.net