Database Reference
In-Depth Information
Figure 11-51
Continued
(b) Graphical representation of the XML Schema
"[POYHUVLRQ HQFRGLQJ 87)"!
$UWLVW
[POQV[VL
KWWSZZZZRUJ;0/6FKHPDLQVWDQFH
[VLQR1DPHVSDFH6FKHPD/RFDWLRQ
&?LQHWSXE?ZZZURRW?'%3?95*?'%3H95*$57,67[VG
$UW6W\OH
0RGHUQ
!
/DVW1DPH
!
0LUR
/DVW1DPH
!
)LUVW1DPH
!
-RDQ
)LUVW1DPH
!
1DWLRQDOLW\
!
6SDQLVK
1DWLRQDOLW\
!
'DWH2I%LUWK
!
'DWH2I%LUWK
!
'DWH'HFHDVHG
!
'DWH'HFHDVHG
!
$UWLVW
!
(c) Schema-Valid XML Document
This first statement not only specifies the document that is to be used for validation, it
also establishes a labeled namespace. Namespaces are a complicated topic in their own right,
and we will not discuss them in this chapter other than to explain the use of labels. In this
first statement, the label
xs
is defined by the expression
xmlns:xs
. The first part of that expres-
sion stands for
xml
name
s
pace, and the second part defines the label
xs
. Notice that all of
the other lines in the document use the label
xs
. The expression
xs:complexType
simply tells
the validating program to look into the namespace called
xs
(here, the one specified as
www
.w3.org/2001/XMLSchema
) to find the definition of the term
complexType
.
The name of the label is up to the designer of the document. You could change xmlns:xs
to xmlns:xsd or to xmlns:mylabel, and you would set xsd or mylabel to point to the w3 docu-
ment. Documents can have multiple namespaces, but that topic is beyond the scope of this
discussion.
Elements and Attributes
As shown in Figure 11-51(a), schemas consist of elements and attributes. Elements are
either simple or complex. Simple elements have a single data item. In Figure 11-51(a), the
elements LastName, FirstName, Nationality, DateOfBirth, and DateDeceased are all simple
elements.
Complex elements contain other elements that can be either simple or complex. In
Figure 11-51(a), the Artist element is complexType. It contains a sequence of five simple ele-
ments: LastName, FirstName, Nationality, DateOfBirth, and DateDeceased. Later you will
see examples of complex types that contain other complex types.
Complex types can have attributes. Figure 11-51(a) defines the attribute ArtStyle. The cre-
ator of an XML document uses this attribute to specify a characteristic about an artist—in this
case, his or her style. The example document in Figure 11-51(c) specifies the ArtStyle for this
artist (Miro) as Modern.
Search WWH ::
Custom Search