[BizTalk development Basics] XPath in orchestration

Source: Internet
Author: User
Tags xpath functions biztalk

In orchestration, we often need:

1) determine the value from the message (for example, extract the isvip in customermessage for different business processing.

2) modify some values in the message and perform business processing. For example, extract the isvip value in customermessage. If isvip is set to true, a shopping coupon of USD 100 will be given.

XPath function Signature: XPath (message, xpathstring)

During development, XPath functions often encounter errors during operation, which makes debugging inconvenient. Therefore, be careful when writing xpathstring. For example, you can use XPath string () to obtain the value of a struct node and try to use local-Name () and namespace-Uri ().

Example:

 <?XML version = "1.0" encoding = "UTF-16"?>

< Salesorder >
< Items >
< Item Code = "Item001" Price = "18.00" Qty = "1" />
< Item Code = "Item002" Price = "18.00" Qty = "2" />
< Item Code = "Item003" Price = "18.00" Qty = "3" />
</ Items >
</ Salesorder >

 

 

1) obtain the number of items in salesorder.

Count (/* [local-Name () = 'salesorder']/* [local-Name () = 'items ']/* [local-Name () = 'item'])

2) obtain the code of the first item

String (/* [local-Name () = 'salesorder']/* [local-Name () = 'items ']/* [local-Name () = 'item'] [1]/@ code)

3) obtain the qty of the first item

 

Number (/* [local-Name () = 'salesorder']/* [local-Name () = 'items ']/* [local-Name () = 'item'] [1]/@ code)

In the development process, sometimes we often have personalized schema, so it involves personalized XPath. At that time, we may have to go to orchestration to find these XPATH and modify it. This is inconvenient,The relative feasible method is to write all the XPath to be used in a helper class or in the configuration file..

 

Xpathnavigator can also be used to perform full unit tests on XPath. See the following example.Code:

1 [Testfixture]
2 Class Testxpathstatements
3 {
4 [Test]
5 Public   Void Testxpathsalesorderitemcount ()
6 {
7 Object Val = Evalxpath ( " Salesorder. xml " , Xpathconstants. salesorder_item_count );
8 }
9
10 Private   Object Evalxpath ( String Xmlinstance, String XPath)
11 {
12 String Filepath = Path. Combine (
13 Path. Combine (appdomain. currentdomain. basedirectory, " Xmlinstance " ),
14 Xmlinstance );
15
16 Using (Streamreader SR =   New Streamreader (filepath ))
17 {
18 Xpathdocument xpathdoc =   New Xpathdocument (SR );
19 Xpathnavigator nav = Xpathdoc. createnavigator ();
20
21 Return Nav. Evaluate (XPath );
22 }
23 }
24 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.