BizTalk: xpath: How to work with empty and Null elements in the Orchestration

The problem is with the Empty-Null cases in the xpath expressions.

Is it possible to separate all these cases in Expression shapes of the Orchestration xpath?

For example, we have the record with element, in such flavors:

 case: "NonEmpty"

ns0:People\
    ns0:Name\Name_0</ns0:Name>
    ns0:IsDependent\IsDependent_0</ns0:IsDependent>
..

case: "Empty"

  ns0:People\
    ns0:Name\</ns0:Name>
    ns0:IsDependent\IsDependent_0</ns0:IsDependent>
..

 case: "OneTag"

ns0:People\
    ns0:Name/\    ns0:IsDependent\IsDependent_0</ns0:IsDependent>
..

 case: "Null"

ns0:People\
  
    ns0:IsDependent\IsDependent_0</ns0:IsDependent>
..

**Is it possible to separate all these cases in Expression shapes of the Orchestration?
**

There is no information into the MSDN about this [http://msdn.microsoft.com/en-us/library/aa561906(BTS.10).aspx]

I tried to use the xpath() function in two variants, one with "string(xpath_expression)" second with "xpath_expression"

Expression Shape:

[

System.Diagnostics.Trace.WriteLine("== with string() ====================================================================");

var_xpathString = "string(/*[local-name()='Root' and namespace-uri()='http://MapTest.IncPerson'\]/\*\[local-name()='People' and namespace-uri()='http://MapTest.IncPerson'\]/\*\[local-name()='Name' and namespace-uri()='http://MapTest.IncPerson'\])";

System.Diagnostics.Trace.WriteLine("[" + System.Convert.ToString(xpath (msg_SourceRoot, var_xpathString)) + "]");

if ( xpath (msg_SourceRoot, var_xpathString) == null)
    { System.Diagnostics.Trace.WriteLine("Name == null"); } 

else if ( xpath (msg_SourceRoot, var_xpathString) == "")
    { System.Diagnostics.Trace.WriteLine("Name == Empty");}

else
    { System.Diagnostics.Trace.WriteLine("Name != null && Name != Empty"); }

System.Diagnostics.Trace.WriteLine("-- no string() --------------------------------------------------------------------");
var_xpathString = "/*[local-name()='Root' and namespace-uri()='http://MapTest.IncPerson'\]/\*\[local-name()='People' and namespace-uri()='http://MapTest.IncPerson'\]/\*\[local-name()='Name' and namespace-uri()='http://MapTest.IncPerson'\]";

System.Diagnostics.Trace.WriteLine("[" + System.Convert.ToString(xpath (msg_SourceRoot, var_xpathString)) + "]");

if ( xpath (msg_SourceRoot, var_xpathString) == null)
    { System.Diagnostics.Trace.WriteLine("Name == null"); }

else if ( xpath (msg_SourceRoot, var_xpathString) == "")
    { System.Diagnostics.Trace.WriteLine("Name == Empty"); }

else
    { System.Diagnostics.Trace.WriteLine("Name != null && Name != Empty");}

 ]

I.e. the "string(xpath_expression)" expression is used in the firs section, the"xpath_expression" is used  in the second.

Result is:

"NonEmpty" == with string() ====================================================================
[Name_0]
Name != null && Name != Empty
-- no string() --------------------------------------------------------------------
[Microsoft.XLANGs.Core.Part+ArrayBasedXmlNodeList]
Name != null && Name != Empty

"Empty"== with string() ====================================================================
[]
Name == Empty
-- no string() --------------------------------------------------------------------
[Microsoft.XLANGs.Core.Part+ArrayBasedXmlNodeList]
Name != null && Name != Empty

"OneTag"== with string() ====================================================================
[]
Name == Empty
-- no string() --------------------------------------------------------------------
[Microsoft.XLANGs.Core.Part+ArrayBasedXmlNodeList]
Name != null && Name != Empty

"Null"== with string() ====================================================================
[]
Name == Empty
-- no string() --------------------------------------------------------------------
[]
Name == null

Conclusion:

* I cannot separate the cases "Empty" and "OneTag"

* I can separate the cases "Empty and "Null" with "xpath_expression", not with "string(xpath_expression)" expression
* "Null" case does not throw an exception.
* xpath expression inside string() works fine to get all three cases ("Empty", "OneTag", "Null") under one "if" statement. And here it returns only "" (Empty string).

Print | posted on Tuesday, November 17, 2009 3:55 PM

This article is part of the GWB Archives. Original Author: Leonid Ganeline

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.