Introduction to XML part 2

XML

I wrote a post in the past about the basics of XML structure and how to build a DTD to define your document type. DTDs describe well how elements are arranged in a document but say very little about the content in the document. Also any element in a document has to have a corresponding declaration in the DTD. These problems and limitations could be solved using schemas. Schemas support rules (and ability to define content) which should be followed in order for a document to be valid. For example lets say that you need to describe a city element. The schema code should look like this:

The xs:element element acts like the !ELEMENT declaration in DTDs. Its name declares a name and its type attribute defines the data type. The xs:string describes the data type of the element “city”. Schemas provide many more features. For example lets say that you want to describe a date element. Date should have some restrictions, for example month should be filled with certain numbers (from 1 to 12) and so on. Enhancing these restrictions in a schema is very easy:

To sum up, schemas are more powerfull than DTDs and allow more flexible data quality control. DTDs though are commonly used and more easy to structure.

Tagged on: , , , ,

One thought on “Introduction to XML part 2

Leave a Reply

Your email address will not be published. Required fields are marked *