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, "Friend", 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, "Friend", which contains only other elements:
We can define a complex element in an XML Schema two different ways:
1. The "Friend" element can be declared directly by naming the element, like this:
If you use the method described above, only the "Friend" element can use the specified
complex type. Note: 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
2. The "Friend" 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
You can also base a complex element on an existing complex element and add some elements, like
Your Query was successfully sent!