0

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?

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54

2 Answers2

1

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.

Johns-305
  • 10,908
  • 12
  • 21
  • Thank you for your answer. I kind of solved it like your way. But I was wondering if it is possible for the BRE to check if the node exists and, if it does exist, check the value of the node. In that way the rule would still be evaluated and that's what I want – Bram Van Strydonck Mar 20 '14 at 14:29
  • 1
    That's pretty much what changing the Selector does, though I would describe it as 'evaluating the Rule only if the node exists'. – Johns-305 Mar 20 '14 at 14:41
  • Yes, I use the same technique, and also sometimes to change the selector to test if the node doesn't exist to take some other action (e.g. raise an warning that it is missing). – Dijkgraaf Mar 20 '14 at 20:08
1

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;
    }