Products | Versions |
---|---|
TIBCO BusinessEvents Enterprise Edition | - |
Not Applicable | - |
Resolution:
Description:
===========
Using TIBCO BusinessEvents XPath functions to extract values from event payload conforming to a predefined schema.
Environment:
===========
All Operating Systems
TIBCO BusinessEvents 4.x,5.x
Resolution:
===========
The attached sample project describes how to access event payload properties conforming to a predefined schema using XPath standard functions in TIBCO BusinessEvents .The schema defines three elements of type string . Element A can occur any number of times as marked by the maxOccurs="unbounded" tag . The event payload contains two values for A , and one each for B and C . The event payload is set in the RuleFunctions.StartUp file. The event properties can also be explored by doing a Ctrl + click on the xslt mapper in RuleFunctions.StartUp . (Refer to attached file EventPayload.png to view the event payload properties).
Sample schema definition (Please refer to Example.xsd in the attached sample project ) :
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.tibco.com/schemas/WebServiceSample/Schema1.xsd2"
targetNamespace="http://www.tibco.com/schemas/WebServiceSample/Schema1.xsd2"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:element ref="a" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="b" minOccurs="0" />
<xs:element ref="c" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="a" type="xs:string"/>
<xs:element name="b" type="xs:string"/>
<xs:element name="c" type="xs:string"/>
</xs:schema>
Using TIBCO BusinessEvents standard XPath functions to extract values from event payload conforming to the above defined schema :
Sample Code . (Refer to Rules.BookInformationRule in the attached sample project .)
String xpath = "/*";
String prefixes = "ns0=http://www.tibco.com/schemas/WebServiceSample/Schema1.xsd2";
String result = XPath.executeWithEvent(xpath, bookdataevent, prefixes);
String[] result2 = XPath.executeXPathWithEvent(xpath, bookdataevent, prefixes);
System.debugOut("result2 = " + result2@length); // result 2 contains all values available
String xpath2 = "$var//payload/ns1:root/ns1:a";
String prefixes2 = "ns1=http://www.tibco.com/schemas/WebServiceSample/Schema1.xsd2";
String result3 = XPath.executeWithEvent(xpath2, bookdataevent, prefixes2);
System.debugOut("result3 = " + result3); // result 3 contains values of a as a string
String xpath21 = "count($var//payload/ns1:root/ns1:a)";
String result31 = XPath.executeWithEvent(xpath21, bookdataevent, prefixes2);
System.debugOut("result31 = " + result31); // result 31 contains the count used as a function
String xpath3 = "$var//ns1:a";
String prefixes3 = "ns1=http://www.tibco.com/schemas/WebServiceSample/Schema1.xsd2";
String[] result4 = XPath.executeXPathWithEvent(xpath3, bookdataevent, prefixes3);
System.debugOut("result4 = " + result4@length); // result 4 conatins the string array of values of a
Steps to run the attached project .
1).Extract the XPathStandardFunctions_with_JMSChannel.zip file .
2).Import the project to TIBCO BusinessEvents studio.
3).Create the ear for the project .
4).Create a run configuration using the JMS.cdd file ( inside the zip archive ) , the ear created in step 3 and default processing unit .
5).Run the project using the run configuration created in step 4.
Attachments :
===========
XPathStandardFunctions_with_JMSChannel.zip
EventPayload.png