Blogz
Sign in to join Michael Dupre's fan club.

The Best Way To Map An XML Database Through An XML Schema (XSD)

by Michael Dupre(2)


Computer programmers frequently fall upon the requirement to modify the way they work with their databases, this is usually the case when say, being a coder you're creating a web app or even a software project therefore you realize that you must change your data mid flow, as an example, changing from xml data into a relational database.

I have commonly worked on projects when the desired goals have shifted and perhaps, new technologies are already announced which has required the need for another type of data methodology.

Having successfully maintained this sort of change in large projects, the process itself is under no circumstances a tricky one; the primary struggle is in mapping the data layout concerning the sender and the destination data.

The simplest way to make this happen is to apply an xml schema (xsd for short), in simple terms an xml schema is a solution to summarize the structure and content of an xml data source.

The schema sets out the blocks of an xml file, just like a DTD. This means schema will set out to express the elements, attributes, child elements, order and amount of child elements etc that could appear in the xml data source.

In order to map your xml database, you can employ the following options, at the present time there is no such thing as a one recommended system or indeed procedure to follow, the below approaches can be regarded as several sensible steps. I'd also add that the solution you operate are going to be manipulated by your own particular circumstances, such as nature and sort of data you would like to map.

Element To Table Mapping

Transforming xml elements into relational database tables would be the most obvious route to take, however it is not absolutely the very best, its suitability can be determined by your data. For instance, mapping an element into a database table will certainly transform the columns to element attributes or the element content into children and so forth.

To map a target element to a relational database table, simply setup the mapping node to retrieve the relevant rows from your 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 suggested when you've got straightforward elements which contain only text string, if your elements is made up of further elements or attributes, your mapping is less likely to achieve success. By default, an element and also attribute of very simple type, maps to the column with the same name in the table.

In the instance below, the <Person.Person> element is of complex type and also, due to this fact, maps by default to the Person.Person table in the selected database. The attributes (BusinessEntityID, FirstName, LastName) of the <Person.Person> element are of simple type and map by default to columns with the same names in the Person.Person table.

<xsd:schema xmlns:xsd=".w3.org/2001/XMLSchema"

 xmlns:sql="urn:schemas-mysite-com:mapping-schema">

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

 <xsd:complexType>

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

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

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

 </xsd:complexType>

 </xsd:element>

</xsd:schema>

Attribute To Column Mapping

Attribute to column mapping is more efficient whenever you would like to map the attributes into columns inside your relational database tables, complimenting them to their given elements. The exemption is in places you have only a given quantity of possible attribute values, on this predicament it would be advisable to have distinct tables for the elements having to deal with each attribute type.

Let’s say you could have an element called “brick”, containing an attribute named “colour”, plus the attributes can only be “red” or “grey”, you could achieve this by setting two tables, one for red bricks and another for grey bricks.

Michael Dupre certainly an skilled practitioner in XML programming and even XML standards and possesses loads of working an understanding of Data Mapping and heavily recommends anyone to Data Mapper.


Article submitted Thursday, February 02, 2012 & read 4 times.

Leave your comments through Blogz:


No comments yet.
2-0-0-0-1-ADSO
Copyright © 2012 IcoLogic, Inc.
Page viewed from Cache.
Page load time: 0.016 seconds.