XML Notes Before Note 4 about XML Schemas
1. Still need to decide what is an element and what is an attribute
2. Still have an easier time manipulating elements than attributes.
3. Attributes are still meta-data.
4. Still have possibility of multiple occurrences of elements, but not of attributes – e.g. in the Airport example, there are multiple aircraft, but each aircraft is of only one type.
5. Still use attributes for IDs and IDREFs.
6. Many more built-in data types are available.
7. When you declare an element its type may be any of the following
- A simple built in type – example in XML_Notes_4 paragraph 9 for Title.
- A simple type defined by restriction – either anonymously or defined (as part of the definition of the element) or defined separately & named.
- A complex type – either anonymously or defined (as part of the definition of the element) or defined separately & named.
See http://www.w3.org/TR/xmlschema-0/#po.xsd for an example where the complex type is defined separately and see XML_Notes_4 paragraph 9 for an example where a complex type is defined anonymously (in line).
8. An element which has one or more children is automatically of a complex type.
9. An element which has attributes is automatically of a complex type, and the attribute declarations go at the end of the element’s declaration.
10. NOTE: Elements and attributes are declared;
Types are defined.
11. An element which is declared and has its children declared within it uses the usual form:
<xs:element name=”myChild” type=”xs:someType” >
an element who children are defined elsewhere uses refs
<xs:element ref=”myChildDefinedElsewhere” >
Examples of both are in XMLX_Notes_4 paragraphs 8 and 9.
12. When a type or an element or an attribute is declared at the top level (as a child of the root element, which is always schema) then you may refer to it elsewhere in the schema. When a type or element or attribute is declared inside another element then you may not refer to it outside that element.
So, global declarations provide reuseability. Think of the address type in the purchase order example (7c above.)
13. All of this is summarized in XML_Notes_7