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 }