Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
November 4, 1998
The new master/detail feature allows you to bind to the current record of a hierarchical record set. In layman's terms, this means that you can now bind the child elements of the current record to a distinct table. For example, let's say you had 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>Candice Calloway</name> <custID>827145</custID> </customer> <item> <name>Fly Paper</name> <price>15.99</price> </item> </order> <order order_number="2235"> <customer> <name>Mandy Jones</name> <custID>998022</custID> </customer> <item> <name>Mosquito Netting</name> <price>38.99</price> </item> </order> </orders>
You could allow your user to surf 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 of the orders, but only for the one in which 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, we see that within the top-level (the "orders") recordset, we can get at the value of the "order_number". We will then allow our user to surf through the orders by "order_number":
<P>ORDER NUMBER: <SPAN DATASRC="#xmlDoc" DATAFLD="order_number"></SPAN></P>
We'll put in a couple of buttons to help them 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 get at the values within the sub-elements of the current record, we will create a table and set that table's DATASRC attribute to "#xmlDoc" exactly as we did above. However, this time we will also set its DATAFLD attribute to "customer". This tells the table that we are going 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"></TD> <TD><SPAN DATAFLD="custID"></SPAN></TD> </TR> </TABLE>
We can 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.
If you have Internet Explorer 5 Beta , press the "Show Example" button to view the page
created above.
Sorry! The interactive exercises require Internet Explorer 5 Beta .
See if you can take the XML from above and create a Web page that will allow a user to surf through the orders by customer name.
Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.