Reading text value from node using XPath function directly in BizTalk orchestrations
July 24th, 2007The XPath function that’s available directly inside BizTalk orchestration is a powerful little tool. However I’ve seen a couple of project where developers just grown tired of it and started creating their own little libraries instead. I’ll be the first to admit that the XPath function isn’t perfect, and it sure doesn’t work like most of the other XPath engines (which is the biggest problem) but it’s still inside the orchestration and you can use it to both read and assign values to a message which is super useful! Basically I don’t see a valid reason for bringing more complexity into your solution by adding another library – as long as you’re just going to read or set value using XPath.
However there is one trick that you should know of when it comes to reading a text value from a node. Basically you have to use both the string() and
text() XPath functions. Both Charles Young and Yossi Dahan has good post on this subject. Also if your new to writing XPath expressions for complex schemas with loads of namespaces and stuff (like schemas in BizTalk) this post could be useful for you.
Finally a nice tool for writing and testing small XPath expression inside Visual Studio (if you don’t want to spend x minutes waiting for XmlSpy to start up …) is XPathmania. Read about it here – I use it all the time!
July 24th, 2007 at 10:48 pm
Hi Richard,
The only thing i dont like about this is having the xpath expression hard coded in the orchestration. Ive seen this a number of times where the schema then changes and you end up with a strange defect somewhere later in the process and you end up tracing it back to the xpath expression being wrong. I tend to prefer the xpath expression being defined in a constant in a C# library which is then tested against a message instance as part of a unit test. The benefit of this is if the expression becomes invalid you would know much quicker.
In what we have done this benefit outweighed the additional complexity to the deployment/solution
July 25th, 2007 at 7:44 am
@Michael: Excellent comment! I totally see the benefit of being able to unit test an expression and catch error quicker.
July 31st, 2007 at 10:06 pm
My question is not related to this post. But I thought you would know a way for my problem. In a BizTalk Map I need to get a node’s inner xml as string. Is it possible? If possible can you tell me how to do it.
August 2nd, 2007 at 2:54 pm
@Raghav: I’ll try and help you via email as I need some further explanation …
August 3rd, 2007 at 1:49 pm
[...] blogged about the Visual Studio extension XPathmania before. It’s a very simple little tool that lets you write and test XPath inside of Visual Studio [...]