Using xpaths in message assignment

Source: Internet
Author: User
Tags biztalk
Microsoft Biztalk Server 2004 using xpaths in message assignment

You can useXpathFunction to assign an XPATH value to a message part, or to assign a value to an XPATH that refers to a message part. for more information on assigning to messages and Message parts, see constructing messages.

NoteThe use ofXpathFunction is not limited to message assignment. You can also use it in any expression, for example:

Copy code
If ((System.Double) xpath(_RequestMessage.part, "number(//book[last()]/price)") == 75.00 && (System.Boolean) xpath(msgBoolean, "string(//boolean)") == false)...

NoteIf you want to assign a value to a string, use the XPath string () function. For example:

Copy code
myString = xpath(msg, "string(/*/book[1]/title)");

NoteThe engine is not Schema-aware, so you can only read values from or write values to a node that exists in the containing message (the complete path must exist ), or the engine will raise an exception. this is true even if you supply a default value.

Assigning to an XPATH in a message part

Consider the following schema:

Copy code
<?xml version="1.0" encoding="utf-16"?><xs:schema xmlns:b="http://schemas.microsoft.com/BizTalk/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:element name="catalog"><xs:complexType><xs:sequence><xs:element minOccurs="1" maxOccurs="unbounded" name="book"><xs:complexType><xs:sequence><xs:element name="title" type="xs:string" /><xs:element name="author"><xs:complexType><xs:sequence><xs:element name="FirstName" type="xs:string" /><xs:element name="LastName" type="xs:string" /></xs:sequence></xs:complexType></xs:element><xs:element name="price" type="xs:string" /></xs:sequence><xs:attribute name="country" type="xs:string" /></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:schema>You can use the XPath function as follows to set values on a document instance of that schema type:construct _ResponseMessage{_ResponseMessage.part = _RequestMessage.part;xpath(_ResponseMessage.part, "/*/book[1]/@country") = "USA";xpath(_ResponseMessage.part, "/*/book[1]/title") = "Legends";xpath(_ResponseMessage.part, "/*/book[1]/author/FirstName") = "A";xpath(_ResponseMessage.part, "/*/book[1]/author/LastName") = "B";xpath(_ResponseMessage.part, "/*/book[1]/price") = 50;}
Assigning to a message part from an XPATH copy code
construct objMessage{objMessage.BooleanPart = xpath("false()");objMessage.IntPart = xpath("100");objMessage.StringPart = xpath("'Hello'");objMessage.StringPart2 = xpath("'World'");}
Using XPath to assign from nodes and node sets

You can also use XPath to assign XML nodes and node sets to an XML element, a class, or a schema-based or class-based message.

Suppose you have an XML-serializable class called Book, and consider the following examples:

Copy code
[Serializable]Class Book {...}

Example one-select the fourth book element from the catalog, and assign it to an XML element variable:

Copy code
myXmlElement = xpath(myMsg, "/catalog/book[3]");

Example two-select the fourth book element from the catalog, and convert it using XML deserialization into a book class instance:

Copy code
myBook = xpath(myMsg, "/catalog/book[3]");

Example three-select the fourth book element from the catalog, and convert it a message of type book:

Copy code
myBookMsg = xpath(myMsg, "/catalog/book[3]");

Example four-select all book elements in the catalog, where mymethod takes an xmlnodeset as a parameter:

Copy code
MyMethod(xpath(myMsg, "/catalog/book"));

Example five-Add a book element to the "bookofthemonth" container:

Copy code
xpath(MyMsg2, "/RecommendedBooks/BookOfTheMonth") = myBook;

Example six-add all books that are priced at twenty or less to a set of recommended books:

Copy code
xpath(MyMsg2, "/RecommendedBooks/BestPriceBooks") = xpath(MyMsg, "/catalog/book[@price <= 20]");

Example seven-Call User code that returns an XML element:

Copy code
xpath(MyMsg2, "/RecommendedBooks/AdvertisedByPartner") = GetPartnerAdvertisedBook();

Before applying examples five and seven:

Copy code
<RecommendedBooks><BookOfTheMonth/><BestPriceBooks/><AdvertisedByPartner/></RecommendedBooks>

After applying examples five and seven:

Copy code
<RecommendedBooks><BookOfTheMonth><Book country="USA"><title>McSharry</title><author><FirstName>Nancy</FirstName><LastName>Jensen</LastName></author></Book></BookOfTheMonth><BestPriceBooks/><AdvertisedByPartner><Book country="USA"><title>The Rooster</title><author><FirstName>Mindy</FirstName><LastName>Martin</LastName></author></Book></AdvertisedByPartner></RecommendedBooks>

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.