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
- Windows Server 2012 : Deploying Storage Spaces (part 3) - Planning a Storage Spaces deployment - Hardware, Performance, Resiliency
- SQL Server 2008 R2 : Advantages of Stored Procedures, Creating Stored Procedures
- Windows Phone 8 : Messaging - Composing a New Message (part 4) - Removing a Message Attachment
- Maintaining Security : Restricting Access on the Computer
- Sharing Your Computer with Others : Delete an Account
- Windows Server 2012 : Enabling Users to Work Anywhere (part 2) - RDS Web Access
- Exchange Server 2007 : Leveraging the Capabilities of the Outlook Web Access Client - Logging On to OWA 2007
- Microsoft Dynamic CRM 4 : Data Migration (part 2) - Scribe Workbench - Target Configuration
- Microsoft Visio 2010 : Creating and Using Shape Data Fields (part 1) - Adding Simple Data Fields
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Inspecting Workbooks
Top 10
- Configuring and Troubleshooting IPv6 in Windows Vista (part 4) - Troubleshooting IPv6 Connectivity
- Configuring and Troubleshooting IPv6 in Windows Vista (part 3) - Configuring IPv6 in Windows Vista Using Netsh , Other IPv6 Configuration Tasks
- Configuring and Troubleshooting IPv6 in Windows Vista (part 2) - Configuring IPv6 in Windows Vista Using the User Interface
- Configuring and Troubleshooting IPv6 in Windows Vista (part 1) - Displaying IPv6 Address Settings
- Deploying IPv6 : IPv6 Enhancements in Windows Vista
- Games and Windows 7 : Games for Windows - LIVE (part 2) - Accessing Games for Windows - LIVE from within Compatible Games
- Games and Windows 7 : Games for Windows - LIVE (part 1) - Using the Games for Windows - LIVE Marketplace
- Sharepoint 2013 : Client-side Programming - Working with the REST API (part 3)
- Sharepoint 2013 : Client-side Programming - Working with the REST API (part 2) - Working with the REST API in JavaScript
- Sharepoint 2013 : Client-side Programming - Working with the REST API (part 1) - Understanding REST fundamentals
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro