Java 2EE and XML Development

Скачать в pdf «Java 2EE and XML Development»

One interesting feature of XQuery is that it contains several types of expressions that can be nested within one another in virtually any combination. The types of expressions available are summarized in table 3.2. The ability to nest these expressions within each other makes performing complex operations on XML data sets amazingly straightforward. For example, you might use XQuery to create new XML structures by joining existing XML documents. One such scenario is depicted in figure 3.4, which shows customer data and order data being joined to create an XML order history data set for a specific customer.

We create the companies.xml and orders.xml files in order to demonstrate an XQuery. The customers.xml file contains the following node:


<customer customer-id=123456>


<customer-name>John Smith</customer-name>


</customer>


The orders.xml file contains the following node:


<order order-id=56789 customer-id=123456> <order-date>01-01-2001</order-date>


<order-total>$59.00</order-total>


</order>


The query to accomplish the join might look something like this: <order-history>


{


for    Builds query


$c in


document(customers.xml)//customer[customer-id = 123456],


$o in


document(orders.xml)//order[customer-id



RETURN


<customer-orders>


{


$c/customer-name


$o/order-date,


$o/order-total


}


</customer-orders> SORT BY(order-date)


}


</order-history>



$c/customer-id]


Retrieves results



t



ts


node-set


О First, this query looks for all customers in the customers.xml file with the attribute customer-id equal to 123456 and stores the result in the $c variable.


t Next, it retrieves all of the orders from the order.xml file with the customer-id attribute equal to 123456 and stores them in $o.

Скачать в pdf «Java 2EE and XML Development»