You are on page 1of 16

XML

Data Modeling
Document Modeling
Document Model
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.
A data model becomes important in the
following scenarios:
-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.
Types of Data Models
There are three major technologies that you can use to create a data
model for your XML documents:
-DTD
-XDR Schema
-XML Schema
Data Modeling with DTD
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.
Example of a 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)>
]>
<!–- 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>
Disadvantages of DTD
-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.
Data Modeling with XDR Schema
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.
An Example of XDR
<?xml version=“1.0” encoding=“UTF-8”?>
<Schema name=“Untitled-schema”
xmlns=“urn:schemas-microsfot-com:xml-data”
xmlns:dt=“urn:schemas-microsoft-com:datatypes”>

<ElementType name=“people” model=“closed” content=“eltOnly” order=“seq”>


<AttributeType name=“xmlns” dt:type=“string”/>
<attribute type=“xmlns”/>
<element type=“person” minOccurs=“1” maxOccurs=“*” />
</ElementType>

<ElementType name=“person” model=“closed” content=“eltOnly” order=“seq”>


<element type=“name” minOccurs=“1” maxOccurs=“1” />
</ElementType>
<ElementType name=“name” model=“closed” content=“eltOnly” order=“seq”>
<element type=“first” minOccurs=“1” maxOccurs=“1” />
<element type=“last” minOccurs=“1” maxOccurs=“1” />
</ElementType>

<ElementType name=“first” model=“closed” content=“textOnly”


dt:type=“string”/>

<ElementType name=“last” model=“closed” content=“textOnly”


dt:type=“string”/>
</Schema>
Data Modeling with XSD
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.
An Example of 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>
<xs:element name=“people”>
<xs:complexType>
<xs:sequence>
<xs:element ref=“person” maxOccurs=“unbounded”/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name=“person”>
<xs:complexType>
<xs:sequence>
<xs:element ref=“name”/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Which Dat Modelling Schema Should I use?
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.

You might also like