A complex element contains other elements and/or attributes.
A complex element is an XML element that contains other elements and/or attributes.
There are four kinds of complex elements:
Note: Each of these elements may contain attributes as well!
A complex XML element, "product", which is empty:
A complex XML element, "employee", which contains only other elements:
A complex XML element, "food", which contains only text:
A complex XML element, "description", which contains both elements and text:
Look at this complex XML element, "employee", which contains only other elements:
We can define a complex element in an XML Schema two different ways:
1. The "employee" element can be declared directly by naming the element, like this:
If you use the method described above, only the "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. You will learn more about indicators in the XSD Indicators chapter.
2. The "employee" element can have a type attribute that refers to the name of the complex type to use:
If you use the method described above, several elements can refer to the same complex type, like this:
You can also base a complex element on an existing complex element and add some elements, like this:
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $7.95/mo SEO Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Free Website Templates Free CSS Templates |
| Make Your Own Website |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|