XML

Summary

XML is a markup language that allows you to create other markup languages. The process of establishing the structure of XML-based markup languages is known as data modeling. The resulting data model for a custom markup language is defined in a construct known as a schema. Two primary approaches exist for creating schemas for XML languages: DTDs and XSDs. There are advantages and disadvantages to each approach, but they are both suitable for most XML applications.

In this tutorial you gained some important insight into document validation and found out what it means for a document to be well formed. You also explored the details of the DTD approach to defining XML schemas, and found out how DTDs are responsible for describing the structure and format of a class of XML documents. You saw that a DTD consists of markup declarations that determine the rules for a custom markup language. In addition to providing a formal set of rules for a markup language, DTDs form a critical part of XML in that they provide a means of validating documents for accuracy. The tutorial culminated with the creation of a complete DTD for the Endurance Training Markup Language (ETML). You also saw a sample XML document created in ETML.

Q&A

Q.

I don't plan on creating any of my own custom markup languages. Do I still need to know the details of DTDs and XSDs?

A.

Yes. In many cases, markup languages aren't documented too well, which means the DTD or XSD for a language may be all you have to go by when it comes to figuring out the format of documents.

Q.

Would I ever want to create both a DTD and an XSD for a custom markup language?

A.

Probably not. The only reason you might do this is if you create a DTD initially for convenience, and later replace it with an XSD as your needs change and as you migrate to tools that demand support for XML Schema (XSDs).

Q.

Why would you ever want to use an internal DTD?

A.

Because an internal DTD is declared directly in an XML document and not in an external file, it applies only to that particular document. Therefore, you should only use an internal DTD for markup declarations that apply to a specific document. Otherwise, all markup declarations should be placed in an external DTD so that they can be reused with other documents.

Q.

Why would you use an attribute over an element when designing a DTD?

A.

Attributes provide tighter constraints on data, can be constrained against a predefined list of possible values, and can have default values. Element content is much less constrained, and is better suited for housing long strings of text and other child elements. A golden rule of XML design is that the more constraints you can impose on a document, the more structured its content will be. Knowing this, you should attempt to fit data into attributes whenever possible.

by BrainBellupdated
Advertisement: