MyArticle » Computers » Programming » Ways To Map An XML Database Using An XML Schema (XSD)

Ways To Map An XML Database Using An XML Schema (XSD)

View PDF | Print View
by: michaeldupre
Total views: 213
Word Count: 670
Date: Tue, 7 Feb 2012 Time: 2:44 AM

Coders often experience the need to alter the manner they work with their databases, it's usually the situation when say, being a developer you might be working on a web app or perhaps software project and then you find you need to alter your data mid flow, as an example, shifting from xml data to a relational database. I have regularly worked on projects in which the goals have moved and in many cases, new technologies are brought in which has necessitated the need for a different sort of data methodology.

Having expertly operated such change in large projects, the procedure itself is in no way a difficult one; the key issue is in mapping the data layout involving the sender and the destination data.

The obvious way to achieve this is by using an xml schema (xsd for short), essentially an xml schema is a approach to illustrate the structure and content of an xml data source. The schema sets out the building blocks of an xml file, much like a DTD. Consequently the schema will set out to express the elements, attributes, child elements, order and quantity of child elements etc that may appear in the xml data source.

To be able to map your xml database, you can use the following solutions, currently there isn't a one recommended process or indeed procedure to adhere to, the below approaches can be regarded as several realistic steps. I would also add that the strategy you take is going to be governed through your own particular circumstances, such as the nature and kind of data you wish to map.

Element To Table Mapping

Transforming xml elements into relational database tables could be the most obvious solution to use, however it is not always the very best, its viability can be driven by your data. Such as, mapping an element into a database table will change the columns to element attributes or the element content into children and the like.

To map a target element to a relational database table, just setup the mapping node to access the appropriate rows from the database, then populate the target elements with values out of your database.

Element To Column Mapping

Mapping elements to columns in your relational database is usually recommended when you have simple elements that have only text string, if your elements contains further elements or attributes, your mapping is unlikely to be successful. By default, an element or attribute of simple type, maps to the column using the same name in the table.

In the illustration below, the <Person.Person> element is of complex type and, subsequently, maps by default to the Person.Person table in the selected database. All the attributes (BusinessEntityID, FirstName, LastName) of the <Person.Person> element are of simple type and map by default to columns with the exact same names in the Person.Person table.

<xsd:schema xmlns:xsd=""


 <xsd:element name="Person.Person" >


 <xsd:attribute name="BusinessEntityID" type="xsd:string" />

 <xsd:attribute name="FirstName" type="xsd:string" />

 <xsd:attribute name="LastName" type="xsd:string" />



Attribute To Column Mapping

Attribute to column mapping will work better when you would want to map the attributes into columns inside your relational database tables, corresponding them to their given elements. The exception is where you simply have a set number of possible attribute values, in this predicament it would be better to have different tables for the elements needing each attribute type.

Let’s say you may have an element designated “brick”, containing an attribute designated “colour”, plus the attributes can only be “red” or “grey”, you could potentially implement it by setting two tables, one for red bricks and another for grey bricks.

About the Author

Michael Dupre undoubtedly an seasoned guru in XML development and also XML standards and possesses loads of working understanding of Data Mapping as well as heavily advises people to Data Mapper.

Latest Articles about: Programming

Popular Articles about: Programming

Rating: Not yet rated