[http://creativecommons.org/licenses/by/3.0/]
This work is licensed under a CC
Attribution 3.0 Unported License [http://creativecommons.org/licenses/by/3.0/]
Schema languages as a general concept in XML are used to (1) prescribe the allowed document structure, and/or (2) validate a document against a description of what is allowed in a document and what isn't. DTDs and XSDs are particularly important schema languages because DTDs are part of XML itself, and XSD was the first major improvement of the rather limited capabilities of DTDs. Recently, however, XSD is increasingly criticized for its complexity, and the RELAX NG schema language is gaining popularity instead. RELAX NG is a grammar-based schema language (like DTD and XSD), but adds a human-friendly syntax, the ability to use datatypes, and it removes the ability to allow validation to change a document.
&
is supported (all is extremely limited)
chess = white, (black, white)*, black?
content model
<!ELEMENT document (heading, chapter) > <!ELEMENT heading (#PCDATA) > <!ELEMENT chapter (heading, para+) > <!ATTLIST chapter id ID #REQUIRED > <!ELEMENT para (#PCDATA) >
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="document"> <xs:complexType> <xs:sequence> <xs:element ref="heading"/> <xs:element ref="chapter"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="heading" type="xs:string"/> <xs:element name="chapter"> <xs:complexType> <xs:sequence> <xs:element ref="heading"/> <xs:element name="para" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="id" type="xs:ID"/> </xs:complexType> </xs:element> </xs:schema>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"> <start><ref name="document"/></start> <define name="document"> <element name="document"> <ref name="heading"/> <ref name="chapter"/> </element> </define> <define name="heading"> <element name="heading"><text/></element> </define> <define name="chapter"> <element name="chapter"> <attribute name="id"><text/></attribute> <ref name="heading"/> <oneOrMore> <element name="para"><text/></element> </oneOrMore> </element> </define> </grammar>
start = document document = element document { heading, chapter } heading = element heading { text } chapter = element chapter { attribute id { text }, heading, element para { text }+ }