1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
XSD Indicators
 
We can control How elements are to be used in documents with indicators
 
There are seven indicators
 
Order indicators : All, Choice, Sequence
 
Occurrence indicators : maxOccurs, minOccurs
 
Group indicators : Group name, attributeGroup name
 
 
 
Occurrence Indicators example
 
The maxOccurs indicator specifies the maximum number of times an element can occur
 
<xs:element name = “person”>
 
<xs:complexType>
 
  <xs:sequence>
 
   <xs:element name = “full_name” type = “xs:string”/>
 
   <xs:element name = “child_name” type = “xs:string” maxOccurs = “10” minOccurs = “0”/>
 
  </xs:sequence>
 
</xs:complexType>
 
</xs:element>

cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
XML example
 
-- Myfamily.xml
 
<?xml version = “1.0” encoding = “UTF-8”?>
 
 
 
<persons xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance
 xsi:noNamespaceSchemaLocation=”family.xsd”>
 
 
 
<person>
 
<full_name>parents1</full_name>
 
<child_name>son1</child_name>
 
</person>
 
 
 
<person>
 
<full_name>parents2</full_name>
 
<child_name>son2</child_name>
 
<child_name>son3</child_name>
 
<child_name>son4</child_name>
 
<child_name>son5</child_name>
 
</person>
 
 
 
<person>
 
<full_name>parents3</full_name>
 
</person>
 
 
 
-- Family.xsd
 
<?xml version = “1.0” encoding = “UTF-8”?>
 
 
 
<xs:schema xmlns:xsi=”http://www.w3.org/2001/XMLSchema” elementFormDefault = “qualified”>
 
 
 
<xs:element name = “persons”>
 
<xs:complexType>
 
  <xs:sequence>
 
    <xs:element name = “person” maxOccurs = “unbounded”>
 
      <xs:complexType>
 
     <xs:sequence>
 
      <xs:element name = “full_name” type = “xs:string”/>
 
      <xs:element name = “child_name” type = “xs:string” minOccurs = “0” maxOccurs = “5”/>
 
     </xs:sequence>
 
    </xs:complexType>
 
</xs:sequence>
 
<xs:complexType>
 
</xs:element>
 
</xs:schema>
 
 
 
** unlimited number of times, use the maxOccurs=”unbounded” statement
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
Group Indicators
 
Used to define related sets of elements
 
 
 
XSD The <any> Element
 
The <any> element enables us to extend the XML document with elements not specified by the schema
 
The <any> and <anyAttribute> elements are used to make EXTENSIBLE documents!!! They allow docuements to contain additional elements that are not declared in the main XML schema.
 
 
 
XSD Element Substitution
 
With XML Schemas, one element can substitute another element
 
 
 
Ex)
 
<xs:element name = “name” type = “xs:string”/>
 
<xs:element name = “navn” substitutionGroup = “name”/>
 
“navn” element is substitutable for “name”
 
 
 
<xs:complexType name = “custinfo”>
 
<xs:sequence>
 
  <xs:element ref = “name”/>
 
</xs:sequence>
 
</xs:complexType>
 
 
 
<xs:element name = “customer” type = “custinfo”/>
 
<xs:element name = “kunde” substitutionGroup = “customer”/>
 
 
 
A valid XML document example
 
<customer>
 
  <name>Tom Cruise</name>
 
</customer>
 
 
 
OR
 
 
 
<kunde>
 
  <navn>Tom Cruise</navn>
 
</kunde>
 
 
 
Blocking Element Substitution
 
<xs:element name = “name” type = “xs:string” block = “substitution”/>
 
<xs:element name = “navn” substitutionGroup = “name”/>
 
“navn” element is substitutable for “name”
 
 
 
<xs:complexType name = “custinfo”>
 
<xs:sequence>
 
  <xs:element ref = “name”/>
 
</xs:sequence>
 
</xs:complexType>
 
 
 
<xs:element name = “customer” type = “custinfo” block = “substitution”/>
 
<xs:element name = “kunde” substitutionGroup = “customer”/>
 
 
 
<kunde>
 
  <navn>Tom Cruise</navn>
 
</kunde>
 
Upper code is NO LONGER VALID
cs


'문돌이의 IT > JSP&Servlet' 카테고리의 다른 글

XSD Schema(XML Schema Definition)4  (0) 2017.01.17
XSD Schema(XML Schema Definition)3  (0) 2017.01.16
XSD Schema(XML Schema Definition)  (0) 2017.01.14
XSD란? XML Schema Definition  (0) 2017.01.10
SOAP이란?  (0) 2017.01.09

+ Recent posts