Logo
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
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 Content Management Server Development : Validating the HtmlPlaceholderControl (part 2) - Checking for an Empty HtmlPlaceholderControl
- Microsoft Excel 2010 : Formatting Subtotals, Applying Multiple Subtotal Function Types (part 1)
- Microsoft Exchange Server 2010 : Managing Connectivity with Hub Transport Servers - Messages in Flight
- Games and Windows 7 : Using the Games Explorer (part 4) - Managing Your Game Controllers and Other Game-Related Hardware
- SQL server 2008 R2 : Reverting to a Database Snapshot for Recovery
- Securing the Workstation : Beginning with Basic Security
- Microsoft Dynamics Ax 2009 : RunBase Framework Extension (part 3) - Adding Property Methods, Adding Constructors
- System Center Configuration Manager 2007 : Distributing Packages - Creating Collections (part 5) - Exclusion Collections
- Adobe Dreamweaver CS5 : Using Library Items and Server-side Includes (part 6) - Applying Server-Side Includes
- Windows Phone 8 : Designing for the Phone - Blend Basics (part 2) - Brushes
Top 10
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 3) - Performing an advanced Active Directory administration task
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 2) - Finding Active Directory administration cmdlets
- Windows Server 2012 : Administering Active Directory using Windows PowerShell (part 1) - Managing user accounts with Windows PowerShell
- Windows Server 2012 : Enabling advanced features using ADAC (part 3) - Creating fine-grained password policies
- Windows Server 2012 : Enabling advanced features using ADAC (part 2) - Configuring fine-grained password policies
- Windows Server 2012 : Enabling advanced features using ADAC (part 1) - Enabling and using the Active Directory Recycle Bin
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Marking a Workbook as Read-Only
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Working with Office Safe Modes
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting External Content Security Options
- Microsoft Excel 2010 : Protecting and Securing a Workbook - Setting Privacy Options - Set Parental Controls for Online Research
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro