ThePlace

Home ] Search ] Resources ] Site Map ] Contact Me ]
Dave's Information Technology Resource

Up ]

What is XML ] Viewing XML ] XML Syntax ] [ Creating XML ] XML and CSS ] XML and DTD ] XML, XSL, and HTML ] The XML DOM ]

--- Creating XML ---

XML and Data Modeling

A lot of attention is given to what XML looks like and how it is structured, not as much is spent on creating XML data structures or XML "data modeling".  Welcome to my humble attempt.

bulletData modeling is the process in which you develop a plan to organize your information. 
bulletTraditionally, this has been used  in designing and implementing databases.  Techniques such as entity-relationship and semantic object modeling have been used for this purpose.
bulletXML data structures are simpler and more like tables in relational databases.

One of the quickest ways to create an XML data model that reflects a database table is to simply copy it.  For example:

bulletTable: customer with the following fields:
bulletlastname
bulletfirstname
bulletaddress
bulletcity
bulletstate
bulletzip
bulletThe XML structure would look like this...

<customer>

<lastname></lastname>
<firstname></firstname>
<address></address>
<city></city>
<state></state>
<zip><zip>

</customer>

This works for most simple table to XML correlations.

Now imagine a join of the customer data with the transaction table and associated tables (in other words, a full blown commerce data model):

bulletAnother table: transaction that includes
bulletcustomer_id
bullettransaction_date
bulletpayment_type
bulletdetail_id
bulletLinked to another table: detail
bulletdetail_id
bulletproduct_id
bulletqty
bulletprice
bulletLinked to the product table
bulletproduct_id
bulletproduct_name

The XML for this would look like this...

<transactions>
    <transaction>
        <trandate>11/7/2003</trandate>
        <paymentmethod>Visa</paymentmethod>
        <customer>
           
<lastname>Smith</lastname>
            <firstname>John</firstname>
            <address>111 Elm St</address>
            <city>Anycity</city>
            <state>MD</state>
            <zip>20888</zip>
        </customer>
        <details>
            <detail>
                   
<productname>battery</productname>
                    <qty>2</qty>
                    <cost>$2.99</cost>
               </detail>
        </details>
    </transaction>
</transactions>

 

How does this work?

bulletThe root element contains all transactions.
bulletEach transaction includes the customer data (name, address, etc.), details, date, and payment.
bulletThe details handle one or more products.
bulletProduct information includes name, quantity, and price.

Is there any other way to accomplish the above design?

bulletYes -- as long as it works as desired, and...
bulletFollows all the rules for well-formed XML.

 

Tips for Designing XML Data Models

bulletLook at a lot of different XML models and understand how they work.
bulletBreak the model down into chunks that make sense.
bulletOrganize like data under a common element (e.g., customer contains, lastname, firstname, etc.).
bulletUnderstand the repeating elements (e.g., the transactions, customers, products).
bulletAs you look at repeating elements, make sure they repeat under the proper parent elements.
bulletPractice, practice, practice.

 

 

 

Home ] Up ] Computer Architecture ] Programming Bootcamp ] Database Bootcamp ] Visual BasicS ] Web Basics ] Web Multimedia ] Web Programming ] Advanced Web Topics ] Developing Web Sites ] Web Glossary ]

Copyright © 1999 - 2005 
ThePlace - Written and Sponsored by Dave Hillman