Thursday, May 9, 2013

Namespaces in E4X

ECMAScript for XML (E4X) extends JavaScript with support for XML-based data manipulation by introducing new XPath-like language features. Apache ODE/WSO2 BPS has an E4X Assign activity to ease Rich Data Manipulation in BPEL using E4X. To use namespaces in E4X queries, follow the syntax namespace::localName in place of a normal element specifier. Eg: To extract the hotelRequestId from the variable submitHotelReviewRequest which has a format similar to the following:
<message>
<submitHotelParameters>
<submitHotelReview xmlns="http://test.bpel.e4x/sample" >
<hotelRequestDetail xmlns="">
<hotelRequestId>007</hotelRequestId>
<origin>CMB</origin>
</hotelRequestDetail>
</submitHotelReview>
</submitHotelParameters>
</message>
view raw gistfile1.xml hosted with ❤ by GitHub
You can use a js snippet as follows:
<bpel:assign validate="no" name="AssignE4X">
<bpel:extensionAssignOperation>
<js:snippet xmlns:js="http://ode.apache.org/extensions/e4x">
<![CDATA[
var xyz = new Namespace('http://test.bpel.e4x/sample');
print("Received Request ID:" + submitHotelReviewRequest.submitHotelReviewParameters.xyz::submitHotelReview.hotelRequestDetail.hotelRequestId);
]]>
</js:snippet>
</bpel:extensionAssignOperation>
</bpel:assign>
view raw gistfile1.xml hosted with ❤ by GitHub

Related Links:
https://developer.mozilla.org/en-US/docs/E4X/Processing_XML_with_E4X
http://www.taval.de/publications/INPROC-2009-25/
http://stackoverflow.com/questions/922668/e4x-grab-nodes-with-namespaces

No comments:

Post a Comment