=head1 XML Terminology To understand the nature of XML Schema it is important to be familiar with some basic XML terminology. An XML B begins with a C> and ends with a C>. For example: The XML B shown below comprises a B (CnameE>), some B (C), and an B (C/nameE>). Mithrandir In additional to character content, an element may include other B nested within in. In this example, the CwizardE ... E/wizardE> element contains the CnameE ... E/nameE> and CaliasE ... E/aliasE> elements. Mithrandir Gandalf The start tag of an element may contain B each comprising of a name and quoted value. Mithrandir An element is said to have a B if it contains character content, the whole character content and nothing but the character content. Mithrandir # simple type If an element has attributes or non-character child elements then it is said to have a B. Frank # complex type (attributes) # complex type (child elements) Frank Sidebottom A complex element defines a B to specify what is permitted within the element in terms of character content and child elements. Content models may be defined in terms of B which specify the child elements that may appear within an element, along with minimum and maximum occurence constraints. These particles may be specified as a B (each element particle must match in order), a B (match just one particle) or B (match all particles but in any order). Particles can be nested recursively allowing content models of arbitrary complexity to be defined. # sequence: Gandalf # name min=1 max=1 Grey # colour min=1 max=1 Mithrandir # alias min=0 max=unbounded Beardy ... If an element accepts both character content and child elements then it is said to have a B.

An HTML paragraph is an example of an XML element with a mixed content model. It can contain plain text and other XML elements

Elements can also have an B in which case the start and end tags can be combined like this:
B The space before the trailing C is optional. However, if you find yourself writing XHTML documents, then you should always add the space to allow HTML browsers to display the markup correctly. =head1 XML Schema Overview A schema is a description of the permitted structure and characteristics of a class of XML instance documents. W3C XML Schema is one particular schema standard and is documented extensively at L. This is an XML fragment which describes a EpersonE. This is termed an "XML instance document". Andy Wardley abw@kfs.org Here is the schema for this element: =head1 XML Schema Perl Modules These Perl modules implement various objects which can be used to define schemata. At the time of writing, these modules offer "minimal conformance" but not "full conformance". Full conformance implies that a schema can be specified as an XML document (like that above) which can be processed automatically to construct an internal schema representation. Currently, schemata must be built "by hand" as Perl programs as shown below. However, we intend to encode the schema for XML Schema itself to build a minimally conformant parser which can bootstrap itself into being a fully conformant parser. use XML::Schema; my $schema = XML::Schema->new(); #------------------------------------------------------------ # define simple type for email addresses my $emailType = $schema->simpleType( name => 'email', base => 'string' ); $emailType->constrain( pattern => '\w+@(\w+\.)+\w+' ); #------------------------------------------------------------ # define complex type for name my $nameType = $schema->complexType( name => 'nameType' ); $nameType->element( name => 'first', type => 'string' ); $nameType->element( name => 'last', type => 'string' ); #------------------------------------------------------------ # define complex type for person my $personType = $schema->complexType( name => 'personType' ); $personType->attribute( name => 'id', type => 'string' ); $personType->element( name => 'name', type => 'nameType' ); $personType->element( name => 'email', type => 'emailType' ); #------------------------------------------------------------ # define key schema element $schema->element( name => 'person', type => 'personType' ); Having constructed a schema model in this way, an XML parser can be generated to parse instances of this schema. my $parser = $schema->parser(); my $result = $parser->parse('person.xml');