The Rules Engine and Repeating Elements

I have found a scenario with the rules engine where the defaults in the Rule Composer do not produce the desired results when dealing with a node that contains repeating elements.


The XML document that I was dealing with had the following structure.




<Item>Description for Item 1</Item>

<Item>Description for Item 2</Item>

<Item>Description for Item 3</Item>




In the Business Rule Composer when I add the schema in the Facts Explorer to the XML Schemas tab, the Rules Composer creates the following XPaths by default on the Item node.


XPath Field:  *[local-name()='Item' and namespace-uri()='']

XPath Selector:  /*[local-name()='Package' and namespace-uri()='']/*[local-name()='Items' and namespace-uri()='']


This set of default XPath statements will only Assert the first of the repeating elements.


Before going into the modification for the XPath statements, lets look at what we are modifying. 


The way that I think of these XPath properties are that the selector XPath isolates a portion of the XML document (you can use many selectors within the same document) and the field XPath identifies specific items with the selector.  In the rules engine, all fields inside the selector are grouped together as an object.  If the selector matches multiple portions of the XML document then there are multiple objects asserted into the rules engine working memory. 


So in our situation we want each Item node of our XML to be a field object


In order to get the rules engine to recognize that these elements repeat, you need to modify the XPath statements as follows:


XPath Field:  '.'  (without the single quotes)

XPath Selector:  /*[local-name()='Items' and namespace-uri()='']/*[local-name()='Item' and namespace-uri()='']'


Once this change has been made, these XPath settings will result in the Assertion of each of the three Item elements.

Comments (0)

Skip to main content