The new master/detail feature allows you to bind to the current record of a hierarchical record set. This means that you can now bind the child elements of the current record to a distinct table. For example, consider the following XML:
<orders> <order order_number="2233"> <customer> <name>John Smith</name> <custID>192883</custID> </customer> <item> <name>Fly Swatter</name> <price>9.99</price> </item> </order> <order order_number="2234"> <customer> <name>Marea Angela Castaneda</name> <custID>827145</custID> </customer> <item> <name>Fly Paper</name> <price>15.99</price> </item> </order> <order order_number="2235"> <customer> <name>Amy Jones</name> <custID>998022</custID> </customer> <item> <name>Mosquito Netting</name> <price>38.99</price> </item> </order> </orders>
You could allow your user to navigate through the orders by ID, displaying only the customer and item information for the current order. Your user would not have to view the information for all orders—only for the one in which he or she is interested.
The key to binding to lower levels in the hierarchy (the details) is to understand the structure of your data. The above XML has three elements within the root (the <orders>) element. Based on the heuristic employed by the XML DSO, each order will be mapped to a rowset containing an "order_number", "customer", and "item" field. The "order_number" column will contain the value of the "order_number" attribute. The "customer" and "item" columns will contain pointers to respective "customer" and "item" recordsets. The "customer" recordset will then contain a "name" and "custID" field with the values of those elements within. The "item" recordset will contain a "name" and "price" field with the values of those elements within.
So, with this in mind, note that within the top-level (the "orders") recordset, you can get to the value of the "order_number." You will then allow your user to navigate through the orders by "order_number."
<P>ORDER NUMBER: <SPAN DATASRC="#xmlDoc" DATAFLD="order_number"></SPAN></P>
Now add some buttons to help users move throughout the "orders" recordset.
<INPUT TYPE=BUTTON VALUE="Previous Order" onclick="xmlDoc.recordset.movePrevious()"> <INPUT TYPE=BUTTON VALUE="Next Order" onclick="xmlDoc.recordset.moveNext()">
To retrieve the values within the child elements of the current record, create a table and set that table's DATASRC attribute to "#xmlDoc" exactly as was done above. However, this time also set its DATAFLD attribute to "customer." This tells the table to bind to data within the "customer" recordset pointed at within the "customer" field of the "orders" recordset.
<TABLE DATASRC="#xmlDoc" DATAFLD="customer" BORDER> <THEAD><TH>NAME</TH><TH>ID</TH></THEAD> <TR> <TD><SPAN DATAFLD="name"></SPAN></TD> <TD><SPAN DATAFLD="custID"></SPAN></TD> </TR> </TABLE>
Then do the same for the data within the "item" element.
<TABLE DATASRC="#xmlDoc" DATAFLD="item" BORDER=1> <THEAD><TR><TH>ITEM</TH><TH>PRICE</TH></TR></THEAD> <TR> <TD><SPAN DATAFLD="name"></SPAN></TD> <TD><SPAN DATAFLD="price"></SPAN></TD> </TR> </TABLE>
Now, as the user clicks the buttons and moves to the next and previous records in the recordset, the data in the tables will change to correspond to the current record.
Click the Show Example button to view the page created above.
See if you can take the above XML and create a Web page that will allow a user to navigate through the orders by customer name.