|
XML Schema |
|
Note: Each of these elements may contain
attributes as well!
Examples of Complex Elements
A complex empty XML element, “employee”
<employee eid=”1234"/>
A complex XML element, “employee”, which
contains only other elements:
<employee>
<firstname>Amit</firstname>
<lastname>Gupta</lastname>
</employee>
A complex XML element, “employee”, which
contains only text:
<employee type=”category”>Programmer</
employee>
A complex XML element, “event”, which
contains both elements and text:
<event>
It occured on <date
lang=”norwegian”>15.05.07</date> ....
</event>
Defining a Complex Element:
Look at this complex XML element,“employee”, which contains only other
elements:
<employee>
<firstname>Amit</firstname>
<lastname>Gupta</lastname>
</employee>
We can define a complex element in an XML
Schema in two different ways:
1. “employee” element can be declared directly
by naming the element, like this:
<xs:element name=”employee”>
<xs:complexType>
<xs:sequence> |
|
<xs:element name=”firstname”
type=”xs:string”/>
<xs:element name=”lastname”
type=”xs:string”/>
</xs:sequence>
</xs:complexType>
</xs:element>
In the above described method only “employee”
element can use the specified complex type.
Note that the child elements, “firstname” and“lastname”, are surrounded by the <sequence>
indicator. This means that the child elements
must appear in the same order as they are
declared.
2. “employee” element can have a type attribute
refering to the name of the complex type to
use:
<xs:element name=”employee”
type=”personinfo”/>
<xs:complexType name=”personinfo”>
<xs:sequence>
<xs:element name=”firstname”
type=”xs:string”/>
<xs:element name=”lastname”
type=”xs:string”/>
</xs:sequence>
</xs:complexType> Using the method described above, several
elements can refer to the same complex type,
like this:
<xs:element name=”employee”
type=”personinfo”/>
<xs:element name=”employer”
type=”personinfo”/>
<xs:element name=”teammember”
type=”personinfo”/>
<xs:complexType name=”personinfo”>
<xs:sequence>
<xs:element name=”firstname”
type=”xs:string”/>
<xs:element name=”lastname”
type=”xs:string”/>
</xs:sequence>
</xs:complexType> |
|
Feb 2008 | Java Jazz Up |21 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
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 ,
Download PDF |
|
|
|
|
|
|
|
|
|