HTML and CSS Reference
In-Depth Information
The Document Type Definition ( DTD ) is a precursor to the XSD and defines the
elements and attributes in an XML document. While the DTD was used to validate the
structure of an XML file, it has been abandoned because the XSD provides more detail
about the XML structure because it can define specific data types to enforce data validity.
A DTD defines an XML document using one data type. In an XSD, you must define the
content by its particular type of data. For example, a DTD cannot define a field as a date,
whereas an XSD can. Moreover, a DTD cannot create and define complex data types in
the same way an XSD can. In an XSD, an element defined as a date must conform to the
format of a date.
An XML Schema Definition is an XML file in itself. It must conform to the
same rules of any XML document to be valid and well-formed. An XSD file contains
the primary components of simple type definitions, complex type definitions, attributes
declarations, and elements. Simple type definitions do not contain child elements nor do
they contain attributes. Complex type definitions contain other elements and attributes.
Attributes are values that appear in start or empty elements. Elements define the
contents of an XML file and the relationship to other elements.
The <schema> element is the root element of every XSD. The <schema> contains
information to identify and associate the namespace to the schema definitions. The xmlns
attribute points to the URI to define the namespace. A namespace is used to prevent
confusion over multiple elements being used by different sources. These elements may
have the same name but have data types. Table H-7 shows the general form of the
<schema> root element of the XSD defining the namespace.
Table H-7 The Root <schema> Element
Root element:
<xs:schema xmlns:xs=""
[targetNamespace="URI "
xmlns="URI "
The xs is the namespace. The xmlns is the XML namespace location and associates the xs to the
schema of all schemas at the Web site. The most used namespaces are xs or xsd.
The optional elements within brackets are targetNamespace that associates other namespace
items with the designated URI. The xmlns defines the default namespace location and the
elementFormDefault indicates that the definition must be namespace qualified.
<xs:schema xmlns:xs="">
To define an XML element, the XSD <element> tag names the element and data
type. Table H-8 shows the general form of the XSD <element> tag.
Table H-8 The <element> Tag Element
General form:
<xs:element name="ield name" type="data type" />
xs: is a namespace, to differentiate this element from any other element that may have the
same name. The name is an attribute to define the field name; type is an attribute to state
one of the valid data types. Simple elements may have an optional default or fix attributes to
assign a default value to a field. The default value is assigned if no other value is assigned;
the fixed value does not allow any other value to be assigned. Most developers use xs or xsd
as a default namespace. This topic uses xs.
<xs:element name="qoh" type="xs:integer" default="0" />
Table H-9 defines the remaining XSD elements that define the structure of any XML
Search WWH ::

Custom Search