Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

BizTalk 2010 Recipes : Orchestrations - Using XPath Queries on Messages

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server