Last Updated: 2004 Comments: <!-- just like html --> but consider using <annotation> <documentation xml:lang="en"> Ransom demand schema Copyright 2000 Brankin.com. All rights reserved. </documentation> </annotation> for docuementation type comments Includes: <include schemaLocation="http://www.brankin.com/schemas/sheep.xsd"/> Note that the namespace of the importing and imported schemas must be identicle. If they are not identical, use import instead (and correctly prefix every external reference thereafter) Simple Types: Cannot contain elements Cannot have attributes [from http://www.w3.org/TR/xmlschema-0/] <xsd:simpleType name="USState"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="AK"/> <xsd:enumeration value="AL"/> <xsd:enumeration value="AR"/> <!-- and so on ... --> </xsd:restriction> </xsd:simpleType> <csd:element name="someName" type="xsd:anyType/> allows anything. In fact xsd:anyType is the default for type. Grouping: Define a block of XML you want to reference later as follows: <xsd:group name="customerAddress"> <xsd:sequence> <xsd:element name="shippingAddress" type="Address"/> <xsd:element name="billingAddress" type="Address"/> </xsd:sequence> </xsd:group> Then ref it later (see gift example) Ordering: Sequence, Choice, All Sequence: Elements must appear in the order they are listed within the sequence block Choice: Only one of the elements in the choice block may appear. Choice must be nested in a sequence block All: Any of the elements in the all block may appear and may appear in any order. All can only be used directly below the complexType / simpleType header and can't be nested. Example: <xsd:complexType name="Gift"> <xsd:sequence> <xsd:choice> <xsd:group ref="socks"/> <xsd:group ref="bookToken"/> </xsd:choice> <xsd:group ref="customerAddress"/> <xsd:element name="Message" type="xsd:string" minOccurs="0"/> </xsd:sequence> <xsd:attribute name="deliveryDate" type="xsd:date"/> </xsd:complexType> Complex Types: Can contain elements Can have attributes, but these must appear after the sequence / choice etc tags (seems to be a .NET 2.0 thing) <xsd:complexType name="UKAddress"> <xsd:sequence> <xsd:element name="line1" type="xsd:string"/> <xsd:element name="line2" type="xsd:string" minOccurs="0"/> <xsd:element name="town" type="xsd:string"/> <xsd:element name="count" type="xsd:string"/> etc. </xsd:sequence> <xsd:attribute name = "version" type="xsd:decimal"/> </xsd:complextType> minOccurs / maxOccurs apply to elements only and equal "1" if not specified. Use maxOccurs="unbounded" to set no upper limit use="required|optional|prohibited" provides the same functionality for attributes default="default value" applies both to elements and attributes. An attribute cannot have a default and use="required|prohibited" or have the fixed attribute as well fixed="xyz" attribute only. Specifies that if the attribute is present, its value must be xyz nillable="true" (elements only) adds 'null' support (nil in XML terms) for the element. An element can be nil while still having attribute data. abstrace="true" (elements only) just like c#. Only dervivates of this element can actually appear in the XML document form = "qualified | unqualified" specifies whether the element needs to be qualified by a namespace id = "???" Optional ref = "some named attribute" The 'any' tag can be used to include arbitarty elements: <element name="htmlExample"> <complexType> <sequence> <any namespace="http://www.w3.org/1999/xhtml" minOccurs="1" maxOccurs="unbounded" processContents="skip"/> </sequence> </complexType> </element> or text [example taken from http://www.w3.org/TR/xmlschema-0/]: <xsd:complexType name="text"> <xsd:complexContent mixed="true"> <xsd:restriction base="xsd:anyType"> <xsd:sequence> <xsd:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/> </xsd:sequence> <xsd:attribute ref="xml:lang"/> </xsd:restriction> </xsd:complexContent> </xsd:complexType> <xs:attribute name="twocharandanumber"><xs:simpleType> <xs:restriction base="xs:string"> <xs:pattern value="[A-Z][A-Z][0-9]"/> </xs:restriction> </xs:simpleType></xs:attribute> Additionally, there is support for the followin: Combinations of elements that are legal and illegal (based on path queries) XslTransform xslt = new XslTransform(); xslt.Load(@"../../ResultToDataGrid.xsl"); XPathDocument xsltDataIn = new XPathDocument("Result.xml"); XmlTextWriter xsltDataOut = new XmlTextWriter("ResultDataGrid.xml", System.Text.Encoding.UTF8); xslt.Transform(xsltDataIn, null, xsltDataOut, null); xsltDataOut.Close();