Fun with XPATH: Ensure the Node Actually Exists

Yes–I’m neck-deep in BizTalk development again and often forget the little things as deadlines quickly approach (or fly right by…).   As such, in an orchestration I built I”m attempting to assign a value to a node in a newly constructed message using the xpath function.

It’s a nice function.  You just use an XPath expression to either select a node, retrieve a value, get a count, or basically anything you can do in XPath.  Here’s the syntax:

xpath(message, "xPathText")

Of course, be sure to do any data conversions necessary to make it work with whatever variable or message, etc, you’re trying to assign it to.

Today, I got this gem of an exception:

ERROR [YOUR_ORCHESTRATION] – The XPath expression [YOUR_XPATH] selected a node which is not valid for property or distinguished field retrieval, or it selected no node at all. Only text-only elements or attributes may be selected.   at Microsoft.XLANGs.Core.Part.XPathStore(Object rValue, String xpath)  at [YOUR_ORCHESTRATION].segment11(StopConditions stopOn)  at Microsoft.XLANGs.Core.SegmentScheduler.RunASegment(Segment s, StopConditions stopCond, Exception& exp)

Although the exception implies I’m trying to grab a promoted property or distinguished field, that wasn’t the case.  It was just a regular node.  However after a little bit more debugging I discovered that the problem wasn’t that the node was promoted or distinguished or just a regular node.  IT WASN’T THERE! (the “no node at all” part of the message)

Yep–just pop me on the head for missing this one.   The message assignment I was attempting will fail everytime when there’s no node to which I can assign my value.  Lesson learned.  Fix the map and/or assignments prior to running the xpath function and all goes well (until the next thing).


About Ed Jones

Ed is a Connected Systems and .NET Specialist for RBA in the Twin Cities. Contact Ed

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: