A document model defines a set of element names and attributes that can appear in an XML document. A document model, more formally and generally known as a data model , describes the logical structure of a set of data. The data model specifies which information a data set contains in terms of the names of the fields, which data each field can contain, and the relationships between fields and other sets of data. Document Model
You want to define an XML vocabulary, and you need to ensure that people can computers produce XML documents that conform on the vocabulary. You want to reduce the cost of creating a new XML-aware application. You want to ensure that XML documents meet a certain level of quality, in terms of their structure and the data that they contain. XML documents are created by people or other applications and are consumed (read) by other applications. A data model becomes important in the following scenarios:
There are three major technologies that you can use to create a data model for your XML documents: DTD XDR Schema XML Schema Types of Data Models
DTD, or Document Type Definition, is a technology that’s part of the XML specification. This means that all validating XML parsers must be able to read and work with a DTD. A validating XML parser can not only read XML documents, but verify that they conform to a specific schema. Data Modeling with DTD
<?xml version=“1.0” encoding=“UTF-8”?> <!– The DTD follows... --> <!DOCTYPE people [ <!ELEMENT people (person+)> <!ELEMENT person (name)> <!ELEMENT name (first, last)> <!ELEMENT first (#PCDATA)> <!ELEMENT last (#PCDATA)> ]> Example of a DTD
<!–- The XML data begins here... --> <people> <person> <name> <first>Erik</first> <last>Westermann</last> </name> </person> <person> <name> <first>Tom</first> <last>Archer</last> </name> </person> </people>
DTDs use a specialized syntax that’s different from XML, making them more difficult to learn for people without a background in SGML or XML DTDs don’t allow you to specify which type of data an element can contain. DTDs have a fixed, non-extensible content model that doesn’t allow developers to create new elements and attributes. DTDs don’t support namespaces. Disadvantages of DTD
XDR, or XML Data Reduced, is an XML vocabulary invented by Microsoft taht allows you to describe the schema of an XML document. The XDR describes that schema in terms of not only the document’s content, but also which types of content are contained in the document’s elements. The primary drawback to using XDR is that it’s limited to Microsoft products and technologies – other vendors don’t support XDR. Data Modeling with XDR Schema
XSD, the XML Schema Definition, is a W3C recommendation that allows you to describe XML schemas using an XML vocabulary. The XSD describes the XML Document in terms of its data types. Data Modeling with XSD
<?xml version=“1.0” encoding=“UTF-8”?> <xs:schema xmlns:xs=“http://www.w3.org/2001/XMLSchema” elementFormDefault=“qualified”> <xs:element name=“first” type=“xs:string”/> <xs:element name=“last” type=“xs:string”/> <xs:element name=“name”> <xs:complexType> <xs:sequence> <xs:element ref=“first”/> <xs:element ref=“last”/> </xs:sequence> </xs:complexType> </xs:element> An Example of XSD
DTDs Have been around for a long time and enjoy broad support from a wide range of products and vendors Generally well-understood XDR Microsoft-specific technology. Limited support in the industry. XSD W3C Standard. Broader acceptance from vendors. New in the market. Which Dat Modelling Schema Should I use?