Browse DevX
Sign up for e-mail newsletters from DevX


Five Practical XQuery Applications : Page 5

XQuery is still a relatively new and unfamiliar XML-based language, but it offers many possibilities for simplifying tasks that today are difficult or tedious. These five practical scenarios should give you ideas for leveraging XQuery in your own applications.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Application 4: Supply Chain Band Aid
One of the costliest areas in a supply chain application is integration. This typically takes the form of incompatible message formats. The buyer has decided to move to something more standard, like RosettaNet, and away from its previous in-house created format. As a supplier, you agree in principal with open standards, but you weren't quite ready to move just yet. The move to RosettaNet is really going to throw a wrench in the works.

What you need is a band-aid, something to get you by until you have time to move your whole application to the new standard. Essentially what you are looking for is a way to map, or transform your existing format to the RosettaNet format, but you don't want to write a bunch of code. Instead, you want to control exactly how the components of the input document get mapped to the schema your application already accepts.

Here's a query that demonstrates how to transform a document snippet into a format suitable for the local application. The customer's RosettaNet format uses an XML vocabulary that represents a sample purchase order and line items, such as:

<ord:item xmlns:ord="http://www.customer.com/orders"> <ord:itemIdentifier>pxz100121</ord:itemIdentifier> <ord:quantity>12</ord:quantity> <ord:price>12:00</ord:price> <ord:currency>USD</ord:currency> <ord:discount>DNBX22</ord:discount> </ord:item>

Your application expects line items represented in the following format:

<po:LineItem itemId="pxz100121" qty="12" unitPrice="12.00" currency="USD" discount="DNBX22" xmlns:po="http://www.myapp.com/po"/>

You need a query that can transform the incoming RosettaNet document into your custom format. Here's a query that achieves the transformation.

declare namespace ord="http://www.customer.com/orders" declare namespace po="http://www.myapp.com/po" for $custlineitem in document("customerPO.xml")//ord:item return <po:LineItem itemId="{$custlineitem/ord:itemIdentifier}" qty="{$custlineitem/ord:quantity}" unitPrice="{$custlineitem/ord:price}" currency="{$custlineitem/ord:currency}" discount="{$custlineitem/ord:discount}"/>

Thanks for your registration, follow us on our social networks to keep up-to-date