Hierarchical XML

XML that comes from a database, whether generated directly from a DataSet or through an XmlDataDocument, is inherently relational. That is, each table is represented by a single element, and its columns are represented by elements within it. Relations between tables are indicated by foreign key constraints and row identifiers. This makes perfect sense for relational data, but sometimes you might want to use a more hierarchical format.

XML is ideal for representing hierarchical data, because it is itself a tree-oriented format. The data from the coupon database could easily be represented in a combination of relational hierarchical XML structures, as shown in Example 11-12.

Example 11-12. Hierarchical representation of coupon database
<AngusHardware> <customers> <customer_id>1</customer_id> <name>Mark's Roofing</name> <address1>99 Beltline Pkwy</address1> <address2>Suite 100</address2> <city>Wannaque</city> <state>NH</state> <zip>05461 </zip> </customers> <coupons> <coupon_code>077GH </coupon_code> <discount_amount>15</discount_amount> <discount_type>0</discount_type> <expiration_date>2002-11-09T14:17:41.6370000-05:00</expiration_date> </coupons> <coupons> <coupon_code>665RQ </coupon_code> <discount_amount>15</discount_amount> <discount_type>0</discount_type> <expiration_date>2002-11-30T00:00:00.0000000-05:00</expiration_date> <coupon_redemptions> <coupon_code>665RQ </coupon_code> <total_discount>21.5</total_discount> <redemption_date>2002-11-10T00:00:00.0000000-05:00</redemption_date> ...

Get .NET & XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.