Based on XSD: http://www.w3schools.com/Schema/default.asp
* example:
* to reference an XSD in an XML document the main node has to have the following attributes:
More about data types - read here: http://www.w3schools.com/Schema/schema_dtypes_string.asp
* example:
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>*
elementFormDefault="qualified"
indicates that all elements in the XML must be namespace qualified* to reference an XSD in an XML document the main node has to have the following attributes:
xmlns="http://www.w3schools.com"
- default namespace declaration-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- make XML Schema Instance namespace available -
xsi:schemaLocation="http://www.w3schools.com location_of_your_schema.xsd"
- location of the schema to be used with given namespace
- simple element (e.g.
<xs:element name="to" type="xs:string"/>
) - can contain only text (i.e. boolean, string, date, etc.), you can also restrict its type; the most common types:
- xs:string
- xs:decimal
- xs:integer
- xs:boolean
- xs:date
- xs:time
* you can also specify a default value for an element; - an attribute - is a simple element (e.g.
<xs:attribute name="xxx" type="yyy"/>
) - you can specify a default or a fixed (cannot be changed) value of an attribute; to make an attribute required you have to specify it, by usinguse="required"
attribute; - complex element - composed of other elements and/or text; can also contain empty elements; there are two ways of defining a complex type:
<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><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>
<xs:complexType name="fullpersoninfo">
<xs:complexContent>
<xs:extension base="personinfo">
<xs:sequence>
... new elements ...
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType> - empty element (i.e. with even no text inside):
<xs:element name="product">
* there are special ways to define a complex element: with text only, with other elements only, with both text and other elements - i nie widze w tym zadnej logiki; for more information on this see: http://www.w3schools.com/Schema/schema_complex_elements.asp
<xs:complexType>
</xs:complexType>
</xs:element>
- restrictions on simple types:
<xs:element name="car">
(more here: http://www.w3schools.com/Schema/schema_facets.asp)
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:restriction_type value="..."/>
...
<xs:restriction>
</xs:simpleType>
</xs:element>
- elements after
"<xs:complexType>
:
*All
- kazde dziecko musi sie pojawic przynajmniej raz, w dowolnej kolejnosci;
*Choice
- jedno z dzieci ma sie pojawic;
*Sequence
- wszystkie dzieci w podanej kolejnosci - attributes in element's definition:
*maxOccurs
*minOccurs
* "For all "Order" and "Group" indicators (any, all, choice, sequence, group name, and group reference) the default value for maxOccurs and minOccurs is 1"
* you can usemaxOccurs="unbounded"
to have the element appearing unlimited number of times - element groups and attribute groups (can be used among other elements/attributes):
- this is a reference to groups of elements: <xs:group ref="persongroup"/>
- and this is a reference to a group of attributes:<xs:element name="person">
read more here: http://www.w3schools.com/Schema/schema_complex_indicators.asp
<xs:complexType>
<xs:attributeGroup ref="personattrgroup"/>
</xs:complexType>
</xs:element>
- "any" element: <
xs:any minOccurs="0"/>
- "anyAttribute" element: <
xs:anyAttribute/>
- what is interesting, with usage of the two above we can create extensible documents; also we can make a document can use e.g. two schemas, one for main part, and another for subparts
-
<xs:element name="name" type="xs:string">
- now "navn" can be used instead of "name"; we can also block an element from others substituting it, by using:
<xs:element name="navn" substitutiongroup="name">block="substitution"
attribute within the original element; read more here: http://www.w3schools.com/Schema/schema_complex_subst.asp
More about data types - read here: http://www.w3schools.com/Schema/schema_dtypes_string.asp
Comments
Want to leave a comment? Visit this post's issue page
on GitHub and just post your comment as the issue's comment (you'll need a GitHub account. What? Like you don't have one yet?!).
Comments: