|
XML Schemas provide us with mechanisms for
describing content model with a lot more accuracy than DTDs.
These use complex type definitions and a new structure, the
<group> element, to build the internal contents of an
element declaration.
The content attribute tells us what elements
describe, although it says nothing about the permitted attributes.
The table given here, shows the Content
attribute value and meaning.
| Content attribute
value |
Meaning |
| Unconstrained |
Content of
any kind |
| Empty |
Empty element |
| Mixed |
Elements and
Character data |
|
Compositors in the schema draft shows how
the content may be composed. These compositors are values
of the order attribute of a <group> element. This new
element gives us a way to provide ordered bodies of elements
in a declaration.
The compositors are shown in the table given
here.
| Compositor keyword |
Meaning |
DTD Equivalent |
| Seq |
Elements must
follow in exact order |
,
(comma) |
| Choice |
Exactly one
of the model elements appears |
|
(pipe) |
|
Syntax of schemas must be in such a way
so as to make it usable in XML. The schemas are hence written
using the syntax of XML, so as to make them applicable to
XML documents.
<element name="Book" />
Supposing we had used <!ELEMENT>
syntax to declare a <Book>
element in a DTD we now use element declarations inside an
XML element. This is declared as shown in the code snippet.
Here the <element /> element
is used to declare an element. The name attribute simply takes
a value of the element we are creating.
Simple elements are composed of a reference
to a data type and a series of attribute declaration or a
reference to an attribute group. This is similar to a DTD
declaration where the element contains only PCDATA, except
that the content is strongly typed.
A new type extends another when it adds
additional content to its source type. In this case, all the
content declared in the source type will appear in the derived
type.
The code here gives an example of how types
are derived. Here, the type FormalPersonName extends from
PersonName and adds an additional property of adding an honorific
element to the derived type.
<type name="PersonName">
<element
name="FirstName" type="string" />
<element
name="MI" type="string" />
<element
name="LastName" type="string" />
</type>
<type name="FormalPersonName"
source="PersonName" derivedBy="extension">
<element
name="honorefic" type="string" />
</type>
<type name="ShortName" source="PersonName"
derivedBy="restriction">
<restrictions>
<element
name="MI" maxOccurs="0" />
</restrictions>
</type>
We can also impose restrictions to
a derived type by giving restriction value in the derived
By attribute and adding the restrictions element, as shown
in the piece of code given here.
The real world relies on concepts of numbers,
strings, and sets. Hence, the programs written in modern programming
languages support elaborate systems of built-in types and
procedures for defining new types. Therefore the addition
of data types to XML Schemas will be a great asset to programmers
using XML for data in their applications.
The support for data types includes the
ability to check the validity of a value in a document. This
also includes in aiding an appropriate conversion from text
to the native type when processing an XML document.
Schema data types are said to have a set
of distinct values called their value space.
Primitive data types are those that are
not defined in terms of other types. They are axiomatic. It
is natural for the XML Schemas proposal to include the classic
XML 1.0 types, but it also adds some types of its own.
The table here gives a list of primitive
types introduced by XML Schema.
| SCHEMA PRIMITIVE
TYPE |
DEFINITION |
| String |
Finite Sequence
of ISO 10646 or Unicode characters, such as "thisisastring". |
| Boolean |
The set (true,
false). |
| Float |
Standard mathematical
concept of real numbers, corresponding to a single
precision 32 bit floating point type. |
| Double |
Standard mathematical
concept of real numbers, corresponding to a double
precision 64 bit floatingpoint type; doubles consists
of a decimal mantissa, followed optionally by the
letter E and an integer exponent, for example 1.06E19. |
| Decimal |
Standard mathematical
concept of a real numeric type; it covers a smaller
range than double, and consists of a sequence of
digits seprated by a period, such as 0.58. |
| Timeinstant |
The combination
of date and time to define a specific instant in
time, encode as a sting, 2003-02-28T10:10:45:00
represents 10:10 on 28 Feb 2003, expressed with
seconds and franctional second. This type is always
expressed YYYY-MM-DDThh:mm:ss:sss, but can be immediately
followed by a Z, to specify that the time is a coordinated
universal time. Alternatively, the time zone can
be specified by supplying a difference fromCUT,
using a+ or a- followed by hh:mm. |
| timeDuration |
A combination
of data and time to define a period. interval or
duration of time. For example, one month is represented
by P0Y1M0T0H0M0S, where the lexical pattern isPnYnMnDTnHnMnS,
and can be preceded by a +(or)-. The representation
may be truncated on right when the finer time intervals
are not needed, for example P2Y3M for 2 years and
3 months. Note that the number pre codes the character
representing the intervals. Seconds may be expressed
by a number including a decimal to represent franctional
second. A minus sign preceding the lexical representation
indicates a negative duration. |
| recurringInstant |
An instant
of time that recurs with some regular frequency,
such as, every day; represented by substituting
a dash for any period not provided in the lexical
pattern for timeInstant. For example, an instant
that occurs at 08:00 every day would be expressed
- T08:00:00:000. |
| Binary |
Arbitrarily
long bodies of binary data. |
| URI |
URI reference. |
|
| Generated and
User Defined Types |
As the name suggests, a generated data type
is built from an existing type. The existing type on which
the generated type is built, is called the base type. XML Schemas
specify some generated types that are broadly useful.
Generated and User Defined Types are shown
in the table.
| GENERATED TYPE |
BASE TYPE |
MEANING |
| Language |
String |
Natural Language
identifier; a token that meets the Language ID production
in XML, for example"en" |
| NM TOKEN |
NMTOKENS |
XML 1.0 NMTOKEN |
| NMTOKENS |
String |
XML 1.0 NMTOKENS |
| Name |
NMTOKEN |
XML 1.0 name |
| Qname |
Name |
XML 1.0 Qualified
Name |
| NCNAME |
Name |
XML 1.0 "non-colonized"
name |
| ID |
NCNAME |
XML 1.0 attribute
type ID |
| IDREF |
IDREFS |
XML 1.0 attribute
type IDREF |
| IDREFS |
String |
XML 1.0 attribute
type IDREFS |
| ENTITY |
ENTITIES |
XML 1.0 ENTITY |
| ENTITIES |
String |
XML 1.0 ENTITIES |
| NOTATION |
NCNAME |
XML 1.0 NOTATION |
| integer |
decimal |
Standard mathematical
concepts of discrete numeric type |
| non-negative-integer |
integer |
Standard mathematical
concepts of non-negative integers |
| positive-integer |
integer |
Standard mathematical
concepts of positive integer |
| non-positive-integer |
integer |
Standard mathematical
concepts of a negative integer, or zero |
| negative-integer |
integer |
Standard mathematical
concepts of a strictly negative integer |
| Date |
recurringInstant |
Standard concept
of a day, that is, an interval beginning at midnight
and lasting 24 hours. |
| Time |
recurringInstant |
Same as the
left-truncated representation for timeInstant hh:mm:ss:sss |
|
 |
 |
Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.
|
|