- By Michael Morrison
- Nov 11, 2005
This chapter is from the book
- 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?
- 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.
- Would I ever want to create both a DTD and an XSD for a custom markup language?
- 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).
- Why would you ever want to use an internal DTD?
- 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.
- Why would you use an attribute over an element when designing a DTD?
- 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.