1.3. XPath

XPath is a navigation language for finding information held in an XML document. Navigation is described using "expressions," which in their basic form are analogous to the paths you use to navigate the filesystem on Windows.

XPath is used by BizTalk messaging and orchestrations to retrieve interesting pieces of data from a message, which can then be used to route the message or perform a conditional business process. As with namespaces, a little understanding of XPath can go a long way toward helping you diagnose problems during development.

An XPath expression returns a node or collection of nodes called a node set and in some cases the result of a function — a integer representing a count for example. The XPath expression /ps:Person/ps:Name will return the Name node of the following XML document.

<ps:Person  xmlns:ps="http://www.wiley.com/person"
xmlns:ad:="http://www.wiley.com/address">
  <ps:Name>Toby</ps:Name>
  <ps:Age>3</ps:Age>
  <ad:Address>
  <ad:Town>Chippenham</ad:Town>
  </ad:Address>
</ps:Person>

As you may have noticed, the namespace prefixes have been used in the XPath expression. Because XPath is "namespace aware," if namespaces are omitted, it will be unable to find the node. Omitting the namespaces in this way will cause XPath to use only the default namespace. So if /Person/Name were to be used, it would not exist outside of the correct namespace.

The .NET code to retrieve the Name element from the preceding document is shown below. Note that the namespace ...

Get Professional BizTalk® Server 2006 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.