Logo
PREGNANCY
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
 
 
Windows Server

BizTalk 2010 Recipes : Orchestrations - Using XPath Queries on Messages

4/14/2011 11:47:49 AM

1. Problem

You need to get and/or set values in a message within an orchestration. There are a number of nodes that cannot be promoted because they are not unique, and you need to be able to access these values.

2. Solution

To access values in a message, you can use XPath. XPath queries are used to navigate the tree of a given XML document and are typically used within orchestration Message Assignment and Expression shapes. BizTalk XPath queries require two parameters: the first parameter references the XML message, and the second is the query path.

As an example, assume that an orchestration message called msgDemo contains the XML shown in Listing 1.

Example 1. Sample XML Instance for XPath Query Example
<ns0:NewHireList xmlns:ns0="http://SampleSolution.NewHireList">
<DateTime>1999-04-05T18:00:00</DateTime>
<ns1:Person xmlns:ns1="http://SampleSolution.Person">
<ID>1</ID>
<Name>S. Jonesy</Name>
<Role>Embedded Programmer</Role>
<Age>40</Age>
</ns1:Person>
<ns1:Person xmlns:ns1="http://SampleSolution.Person">
<ID>2</ID>
<Name>D. Hurley</Name>
<Role>Artist</Role>
<Age>45</Age>
</ns1:Person>
</ns0:NewHireList>

The following steps demonstrate getting values, getting a node count, getting an entire XML node, and setting values.

  1. To get the value of the <DateTime> element, use the following XPath query. The output of this query is 1999-04-05T18:00:00.

    xpath(msgDemo,"string(//*[local-name()='DateTime'])")

  2. To get the value of the <Name> element that is in the same <Person> node as the <ID> which is equal to 2, use the following XPath query. The output of this query will be D. Hurley.

    xpath(msgDemo,"string(//*[local-name()='Name' and ../*
    [local-name()='ID'] = '2'])")

  3. To get the count of <Person> nodes within the document, use the following XPath query. The output of this query is 2.

    xpath(msgDemo,"count(//*[local-name()='Person'])")

  4. To get the entire XML node representation of the second <Person> node, use the following XPath query. Note that this requires formatting the query using the System.String.Format function. The result of this query will be a full XML node.

    strXPathQuery = System.String.Format("//*[local-name()='Person'][{0}]",2);
    xmlDoc = xpath(msgIncoming,strXPathQuery);

    <ns1:Person xmlns:ns1="http://SampleSolution.Person">
    <ID>2</ID>
    <Name>D. Hurley</Name>
    <Role>Artist</Role>
    <Age>45</Age>
    </ns1:Person>

  5. To set the value of the <DateTime> element, use the following XPath query. Note that this must be done in a Message Assignment shape, since the value of the message is changing. The message used must first be constructed.

    xpath(msgDemo, "//*[local-name()='DateTime']") = strDateTime;

3. How It Works

This recipe's solution demonstrated several of the many uses of XPath. One question that often arises is when to use XPath instead of using promoted properties. The ability to promote properties is limited. Elements that repeat within a schema cannot be promoted. Only unique values can be promoted. When you need to set the value of repeating nodes, XPath is the quickest and most versatile approach.

Other -----------------
- SharePoint 2010 : Working with the Other Standard Tools in a Document Library (part 4)
- SharePoint 2010 : Working with the Other Standard Tools in a Document Library (part 3)
- SharePoint 2010 : Working with the Other Standard Tools in a Document Library (part 2)
- SharePoint 2010 : Working with the Other Standard Tools in a Document Library (part 1)
- BizTalk 2010 Recipes : Orchestrations - Configuring Parallel Convoys
- BizTalk 2010 Recipes : Orchestrations - Maintaining Message Order
- Windows Server 2008 Server Core : Working with Performance Information (part 3)
- Windows Server 2008 Server Core : Working with Performance Information (part 2)
- Windows Server 2008 Server Core : Working with Performance Information (part 1) - Managing Performance Logs and Alerts with the LogMan Utility
- Windows Server 2008 R2 : Overview of Failover Clusters
- Windows Server 2008 R2 Clustering Technologies
- Building Fault-Tolerant Windows Server 2008 R2 Systems
- SharePoint 2010 PerformancePoint Services : Creating Dashboards in the Browser
- SharePoint 2010 PerformancePoint Services : Dashboards in Dashboard Designer (part 4) - Using the TheGreenOrange Data Source Option
- SharePoint 2010 PerformancePoint Services : Dashboards in Dashboard Designer (part 3) - Working with Filters on Dashboards
- SharePoint 2010 PerformancePoint Services : Dashboards in Dashboard Designer (part 2) - Dashboard Zones & Dashboard Pages
- SharePoint 2010 PerformancePoint Services : Dashboards in Dashboard Designer (part 1) - Creating and Deploying a Dashboard
- SharePoint 2010 PerformancePoint Services : Web Part Connections
- BizTalk 2010 Recipes : Orchestrations - Configuring Basic Correlations
- BizTalk 2010 Recipes : Orchestrations - Using the Call Orchestration and Start Orchestration Shapes
 
 
Most view of day
- Microsoft Lync Server 2013 : Configuring the Director (part 1) - SRV Records, Web Services FQDN Overrides
- Microsoft Exchange Server 2007 : Implementing Client Access and Hub Transport Servers - Transport Pipeline
- Adobe Photoshop CS5 : Letting Camera Raw Auto-Correct Your Photos, Adding Snap to Your Images Using the Clarity Slider
- Conducting Research in OneNote 2010 : Researching a Topic, Customizing the Research Task Pane
- Microsoft Access 2010 : Viewing the Design of a Report
- Exchange Server 2007 : Deploying a Cluster Continuous Replication Mailbox Cluster (part 1)
- Microsoft Exchange Server 2010 : Completing Transport Server Setup (part 6) - Verifying Edge Subscriptions, Removing Edge Subscriptions
- Windows 7 Mobility Features : Working with the Windows 7 User Interface
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 2) - TodoService, TodoItemViewModel
- HP ProLiant Servers AIS : Memory and Cache
Top 10
- Windows Server 2012 : Configuring IPsec (part 7) - Configuring connection security rules - Monitoring IPsec
- Windows Server 2012 : Configuring IPsec (part 6) - Configuring connection security rules - Creating a custom rule, Configuring authenticated bypass
- Windows Server 2012 : Configuring IPsec (part 5) - Configuring connection security rules - Creating an authentication exemption rule, Creating a server-to-server rule, Creating a tunnel rule
- Windows Server 2012 : Configuring IPsec (part 4) - Configuring connection security rules - Types of connection security rules, Creating an isolation rule
- Windows Server 2012 : Configuring IPsec (part 3) - Configuring IPsec settings - Customizing IPsec tunnel authorizations, Configuring IPsec settings using Windows PowerShell
- Windows Server 2012 : Configuring IPsec (part 2) - Configuring IPsec settings - Customizing IPsec defaults
- Windows Server 2012 : Configuring IPsec (part 1) - Understanding connection security
- Microsoft Project 2010 : Linking Tasks (part 8) - Auditing Task Links,Using the Task Inspector
- Microsoft Project 2010 : Linking Tasks (part 7) - Creating Links by Using the Mouse,Working with Automatic Linking Options
- Microsoft Project 2010 : Linking Tasks (part 6) - Creating Links by Using the Entry Table
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro