BizTalk Business Rules Check on node existance and value

1.5k views Asked by At

I have the following problem. I want to execute a policy that checks for existance of a node and after that it should check if the value is greater than 0.

So lets say we have "xmlDoc" and I want to check if the node "test" exists and if the value of "test" is greater than 0.

<xmlDoc>
    <test>5</test>
</xmlDoc>

When the node exists, there is no problem. When the node is missing though, all hell breaks lose.. It is obvious why he crashes. He can't find the node "test" so he can't check its value.

My question: is it possible in the BizTalk BRE to check on existance and on value of a node without it crashes?

2

There are 2 answers

3
DTRT On

There is the 'exists' Predicate on the list of Conditions, however, this doesn't always work since value fact is also evaluated.

One way I've found to address this is by creating a Vocabulary item and adjusting the Selector to point to the Element that may not exist, "text" in your case.

Then the XPath field would be the /text() node.

This way, if the Selector path returns null, the BRE knows the fact doesn't exist so no Rule that requires it will be evaluated.

0
Ratnakar Chinchkar On

If not exist check is performed alongwith value check, BRE does not work as expected.

Solution :

Below function will return node value and empty string if node does not exist. Use return value of this function to perform value check.

claim : XML document. path : XML path.

    public static string GetXMLPathValue(TypedXmlDocument claim, string path)
    {
        string nodeContent = string.Empty;

        if (claim.Document.SelectSingleNode(path) != null)
            return claim.Document.SelectSingleNode(path).InnerXml;
        return nodeContent;
    }