It's a fact of life that XML, which stands for eXtensible Markup Language, is invading our lives more and more as programmers, and I feel this is a good thing. The reason being XML has the ability to cross all sorts of boundaries, and probably the only chance we have to obtain a truly independent, cross-platform data transfer format.
We will discuss both DTDs and Schemas you can decide which to use. A DTD is a text file that defines the structure of an XML document, but DTDs isn’t XML – it is completely separate syntax.
Let us look at a typical DTD – say you have Employees table in your database that had fields like emp_id, emp_lname, emp_fname, phone, address, zip. Then the XML document generated for this Employee from the database will look this below.
This is actually quite simple it states that this document comprises zero or more employee elements. The plus sign on the end of EMPLOYEE says one or more. Each EMPLOYEE element is made up of six other elements. And each of these sub-elements contains character data (CDATA).
There are two real flaws with DTD: • They are not XML as such • You cannot specify data types such as integer, data and so on.
Because of this Microsoft proposed Schemas to the W3C. If we converted the above DTD into a Schema it will look something like this:
<Schema ID=”EMPLOYEE”>
<ELEMENT name = “emp_id”/>
<ELEMENT name = “emp_lname”/>
<ELEMENT name = “emp_fname”/>
<ELEMENT name = “phone”/>
<ELEMENT name = “address”/>
<ELEMENT name = “zip”/>
</Schema>
With the addition of data types display will look like below.
<Schema ID=”EMPLOYEE”>
<ELEMENT name = “emp_id” type = “string”/>
<ELEMENT name = “emp_lname” type = “string”/>
<ELEMENT name = “emp_fname” type = “string”/>
<ELEMENT name = “phone” type = “string”/>
<ELEMENT name = “address” type = “string”/>
<ELEMENT name = “zip” type = “string”/>
</Schema>
Namespaces:
One problem with XMl is you can give an element almost any name. Unfortunately this means there is good chance you’ll pick the same name as someone else. This is where namespaces come in, as namespaces uniquely identifies the schema to which elements belong. Namespaces are added to XML document by defining the xmlns attributes in the root tag, which requires Uniform resource Identifier (URI).