diff --git a/Doc/Sda1/xmlschema.xml b/Doc/Sda1/xmlschema.xml index e4f385e408fc2f99b6104354cb05e347c4fc6c05..87ebd4754d1985d017dd4367103e9e74b417ec8b 100644 --- a/Doc/Sda1/xmlschema.xml +++ b/Doc/Sda1/xmlschema.xml @@ -1,158 +1,157 @@ - <chapter xml:id="xmlSchema" version="5.0" xmlns="http://docbook.org/ns/docbook" - xmlns:xlink="http://www.w3.org/1999/xlink" - xmlns:xi="http://www.w3.org/2001/XInclude" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns:m="http://www.w3.org/1998/Math/MathML" - xmlns:html="http://www.w3.org/1999/xhtml" - xmlns:db="http://docbook.org/ns/docbook"> - - - <title>Beyond well- formedness</title> - - <section xml:id="motivationSchema"> - <title>Motivation</title> - - <para>So far we are able to create XML documents containing - hierarchically structured data. We may nest elements and thus create - tree structures of arbitrary depth. The only restrictions being imposed - by the XML standard are the constraints of well - formedness. For many - purposes in software development this is not sufficient.</para> - - <para>A company named <productname>Softmail</productname> might - implement an email system which uses <link - linkend="memoWellAttrib">memo</link> document files as low level data - representation serving as a persistence layer. Now a second company - named <productname>Hardmail</productname> wants to integrate mails - generated by <productname>Softmail</productname>'s system into its own - business product. The <productname>Hardmail</productname> software - developers might <emphasis>infer</emphasis> the logical structure of - <productname>Softmail</productname>'s email representation but the - following problems arise:</para> - - <itemizedlist> - <listitem> - <para>The logical structure will in practice become more complex: - E-mails may contain attachments leading to multi part messages. - Additional header information is required for standard Internet mail - compliance. This adds additional complexity to the XML structure - being mandatory for data representation. Relying only on - well-formedness the specification of an internal E-mail format can - only be achieved <emphasis>informally</emphasis>. Thus a rule like - <quote>Each E-mail must have a subject</quote> may be written down - in the specification. A software developer will code these rules but - probably make mistakes as the set of rules grows.</para> - - <para>In contrast a RDBMS based solution offers to solve such - problems in a declarative manner: A developer may use a <code>NOT - NULL</code> constraint on a subject attribute of type - <code>VARCHAR</code> thus inhibiting empty subjects.</para> - </listitem> - - <listitem> - <para>As <productname>Softmail</productname>'s product evolves its - internal E-mail XML format is subject to change due to functional - extensions and possibly bug fixes both giving rise to - interoperability problems.</para> - </listitem> - </itemizedlist> - - <para>Generally speaking well formed XML documents lack grammar - constraints as being available for programming languages. In case of - RDBMS developers can impose primary-, foreign and <code>CHECK</code> - constraints in a <emphasis>declarative</emphasis> manner rather than - hard coding them into their applications (A solution bad programmers are - in favour of though...). Various XML standards exist for declarative - constraint definitions namely:</para> - - <itemizedlist> - <listitem> - <para>DTDs</para> - </listitem> - - <listitem> - <para><link xlink:href="http://www.w3.org/XML/Schema">XML - Schema</link></para> - </listitem> - - <listitem> - <para><link - xlink:href="http://www.relaxng.org">RelaxNG</link></para> - </listitem> - </itemizedlist> +<?xml version="1.0" encoding="UTF-8"?> +<chapter version="5.0" xml:id="xmlSchema" + xmlns="http://docbook.org/ns/docbook" + xmlns:xlink="http://www.w3.org/1999/xlink" + xmlns:xi="http://www.w3.org/2001/XInclude" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:m="http://www.w3.org/1998/Math/MathML" + xmlns:html="http://www.w3.org/1999/xhtml" + xmlns:db="http://docbook.org/ns/docbook"> + <title>Beyond well- formedness</title> + + <section xml:id="motivationSchema"> + <title>Motivation</title> + + <para>So far we are able to create XML documents containing hierarchically + structured data. We may nest elements and thus create tree structures of + arbitrary depth. The only restrictions being imposed by the XML standard + are the constraints of well - formedness. For many purposes in software + development this is not sufficient.</para> + + <para>A company named <productname>Softmail</productname> might implement + an email system which uses <link linkend="memoWellAttrib">memo</link> + document files as low level data representation serving as a persistence + layer. Now a second company named <productname>Hardmail</productname> + wants to integrate mails generated by + <productname>Softmail</productname>'s system into its own business + product. The <productname>Hardmail</productname> software developers might + <emphasis>infer</emphasis> the logical structure of + <productname>Softmail</productname>'s email representation but the + following problems arise:</para> + + <itemizedlist> + <listitem> + <para>The logical structure will in practice become more complex: + E-mails may contain attachments leading to multi part messages. + Additional header information is required for standard Internet mail + compliance. This adds additional complexity to the XML structure being + mandatory for data representation. Relying only on well-formedness the + specification of an internal E-mail format can only be achieved + <emphasis>informally</emphasis>. Thus a rule like <quote>Each E-mail + must have a subject</quote> may be written down in the specification. + A software developer will code these rules but probably make mistakes + as the set of rules grows.</para> + + <para>In contrast a RDBMS based solution offers to solve such problems + in a declarative manner: A developer may use a <code>NOT NULL</code> + constraint on a subject attribute of type <code>VARCHAR</code> thus + inhibiting empty subjects.</para> + </listitem> + + <listitem> + <para>As <productname>Softmail</productname>'s product evolves its + internal E-mail XML format is subject to change due to functional + extensions and possibly bug fixes both giving rise to interoperability + problems.</para> + </listitem> + </itemizedlist> + + <para>Generally speaking well formed XML documents lack grammar + constraints as being available for programming languages. In case of RDBMS + developers can impose primary-, foreign and <code>CHECK</code> constraints + in a <emphasis>declarative</emphasis> manner rather than hard coding them + into their applications (A solution bad programmers are in favour of + though...). Various XML standards exist for declarative constraint + definitions namely:</para> + + <itemizedlist> + <listitem> + <para>DTDs</para> + </listitem> + + <listitem> + <para><link xlink:href="http://www.w3.org/XML/Schema">XML + Schema</link></para> + </listitem> + + <listitem> + <para><link xlink:href="http://www.relaxng.org">RelaxNG</link></para> + </listitem> + </itemizedlist> + </section> + + <section xml:id="dtdBasic"> + <title>XML Schema</title> + + <section xml:id="dtdFirstExample"> + <title>Structural descriptions for documents</title> + + <para>As an example we choose documents of type + <emphasis>memo</emphasis> as a starting point. Documents like the + example from <xref linkend="memoWellAttrib"/> may be + <emphasis>informally</emphasis> described to be a sequence of the + following mandatory items:</para> + + <figure xml:id="figure_memo_informalconstraints"> + <title>Informal constraints on <tag class="element">memo</tag> + document instances</title> + + <itemizedlist> + <listitem> + <para><emphasis>Exactly one</emphasis> sender.</para> + </listitem> + + <listitem> + <para><emphasis>One or more</emphasis> recipients.</para> + </listitem> + + <listitem> + <para>Subject</para> + </listitem> + + <listitem> + <para>Content</para> + </listitem> + </itemizedlist> + + <para>In addition we have:</para> + + <itemizedlist> + <listitem> + <para>A date string <emphasis>must</emphasis> be supplied</para> + </listitem> + + <listitem> + <para>A priority <emphasis>may</emphasis> be supplied with allowed + values to be chosen from the set of values <tag + class="attvalue">low</tag>, <tag class="attvalue">medium</tag> or + <tag class="attvalue">high</tag>.</para> + </listitem> + </itemizedlist> + </figure> + + <para>All these fields contain ordinary text to be filled in by a user + and shall appear exactly in the defined order. For simplicity we do not + care about email address syntax rules being described in <link + xlink:href="http://www.w3.org/Protocols/rfc822">RFC based address + schemes</link>. We will see how the <emphasis>constraints</emphasis> + mentioned above can be modelled in XML by an extension to the concept of + well formed documents.</para> </section> - <section xml:id="dtdBasic"> - <title>XML Schema</title> - - <section xml:id="dtdFirstExample"> - <title>Structural descriptions for documents</title> - - <para>As an example we choose documents of type - <emphasis>memo</emphasis> as a starting point. Documents like the - example from <xref linkend="memoWellAttrib"/> may be - <emphasis>informally</emphasis> described to be a sequence of the - following mandatory items:</para> - - <figure xml:id="figure_memo_informalconstraints"> - <title>Informal constraints on <tag class="element">memo</tag> - document instances</title> - - <itemizedlist> - <listitem> - <para><emphasis>Exactly one</emphasis> sender.</para> - </listitem> - - <listitem> - <para><emphasis>One or more</emphasis> recipients.</para> - </listitem> - - <listitem> - <para>Subject</para> - </listitem> - - <listitem> - <para>Content</para> - </listitem> - </itemizedlist> - - <para>In addition we have:</para> - - <itemizedlist> - <listitem> - <para>A date string <emphasis>must</emphasis> be supplied</para> - </listitem> - - <listitem> - <para>A priority <emphasis>may</emphasis> be supplied with - allowed values to be chosen from the set of values <tag - class="attvalue">low</tag>, <tag class="attvalue">medium</tag> - or <tag class="attvalue">high</tag>.</para> - </listitem> - </itemizedlist> - </figure> - - <para>All these fields contain ordinary text to be filled in by a user - and shall appear exactly in the defined order. For simplicity we do - not care about email address syntax rules being described in <link - xlink:href="http://www.w3.org/Protocols/rfc822">RFC based address - schemes</link>. We will see how the <emphasis>constraints</emphasis> - mentioned above can be modelled in XML by an extension to the concept - of well formed documents.</para> - </section> - - <section xml:id="section_memo_machinereadable"> - <title>A machine readable description</title> + <section xml:id="section_memo_machinereadable"> + <title>A machine readable description</title> - <para>We now introduce an example of an XML schema. It allows for the - specification of additional constraints to both element nodes and - their attributes. Our set of <link - linkend="figure_memo_informalconstraints" revision="">informal - constraints</link> on memo documents may be expressed as:</para> + <para>We now introduce an example of an XML schema. It allows for the + specification of additional constraints to both element nodes and their + attributes. Our set of <link linkend="figure_memo_informalconstraints" + revision="">informal constraints</link> on memo documents may be + expressed as:</para> - <figure xml:id="figure_memo_dtd"> - <title>A schema to describe memo documents.</title> + <figure xml:id="figure_memo_dtd"> + <title>A schema to describe memo documents.</title> - <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -160,13 +159,13 @@ <xs:complexType> <xs:sequence> <co xml:id="memodtd_memodef"/> <xs:element name="from" type="xs:string"/> <co - xml:id="memodtd_elem_from"/> + xml:id="memodtd_elem_from"/> <xs:element name="to" minOccurs="1" maxOccurs="unbounded" type="xs:string"/> <xs:element name="subject" type="xs:string"/> <xs:element name="content" type="xs:string"/> </xs:sequence> <xs:attribute name="date" type="xs:date" use="required"/> <co - xml:id="memodtd_memo_attribs"/> + xml:id="memodtd_memo_attribs"/> <xs:attribute name="priority" type="Priority" use="optional"/> </xs:complexType> @@ -182,138 +181,148 @@ </xs:schema></programlisting> - <calloutlist> - <callout arearefs="memodtd_memodef"> - <para>A <tag class="element">memo</tag> consists of a sender, at - least one recipient, a subject and content.</para> - </callout> - - <callout arearefs="memodtd_memo_attribs"> - <para>A <tag class="element">memo</tag> has got one required - attribute <varname>date</varname> and an optional attribute - <varname>priority</varname> being restricted to the three - allowed values <tag class="attvalue">low</tag>, <tag - class="attvalue">medium</tag> and <tag - class="attvalue">high</tag> being defined by a separate <tag - class="starttag">xs:simpleType</tag> directive.</para> - </callout> - - <callout arearefs="memodtd_elem_from"> - <para>A <tag class="starttag">from</tag> element consists of - ordinary text. This disallows XML markup. For example - <code><from>Smith & partner</from></code> is - disallowed since XML uses the ampersand (&) to denote the - beginning of an entity like <tag class="genentity">auml</tag> - for the German a-umlaut (ä). The correct form is - <code><from>Smith &amp; partner</from></code> - using the predefined entity <tag class="genentity">amp</tag> as - an escape sequence for the ampersand.</para> - - <para><code>type="xs:string"</code> is a built in XML Schema - type representing a restricted version of ordinary strings. - Without digging into details a <code>xs:string</code> string - must not contain any markup code like e.g. <tag - class="starttag">msqrt</tag>. This ensures that a string does - not interfere with the document's XML markup.</para> - </callout> - </calloutlist> - </figure> - - <para>We notice our schema's syntax itself is an XML document.</para> - - <para>From the viewpoint of software modeling an XML Schema instance - is a <emphasis>schema</emphasis> describing the syntax of a class of - XML document instances adhering to it. In the context of XML - technologies <link xlink:href="http://www.w3.org/XML/Schema">XML - Schema</link> is one of several language alternatives which allow for - XML document structure descriptions.</para> - - <para>Readers being familiar with <abbrev - xlink:href="http://en.wikipedia.org/wiki/Backus-Naur_form">BNF</abbrev> - or <abbrev - xlink:href="http://en.wikipedia.org/wiki/Extended_Backus_Naur_form">EBNF</abbrev> - will be able to understand the grammatical rules being expressed - here.</para> - - <productionset> - <title>A message of type <tag class="starttag">memo</tag></title> - - <production xml:id="memo.ebnf.memo"> - <lhs>Memo Message</lhs> - - <rhs>'<memo>' <nonterminal - def="#memo.ebnf.sender">Sender</nonterminal> [<nonterminal - def="#memo.ebnf.recipient">Recipient</nonterminal>]+ <nonterminal - def="#memo.ebnf.subject">Subject</nonterminal> <nonterminal - def="#memo.ebnf.content">Content</nonterminal> - '</memo>'</rhs> - </production> - - <production xml:id="memo.ebnf.sender"> - <lhs>Sender</lhs> - - <rhs>'<from>' <nonterminal def="#memo.ebnf.text"> Text - </nonterminal> '</from>'</rhs> - </production> - - <production xml:id="memo.ebnf.recipient"> - <lhs>Recipient</lhs> - - <rhs>'<to>' <nonterminal def="#memo.ebnf.text"> Text - </nonterminal> '</to>'</rhs> - </production> - - <production xml:id="memo.ebnf.subject"> - <lhs>Subject</lhs> - - <rhs>'<subject>' <nonterminal def="#memo.ebnf.text"> Text - </nonterminal> '</subject>'</rhs> - </production> - - <production xml:id="memo.ebnf.content"> - <lhs>Content</lhs> - - <rhs>'<content>' <nonterminal def="#memo.ebnf.text"> Text - </nonterminal> '</content>'</rhs> - </production> - - <production xml:id="memo.ebnf.text"> - <lhs>Text</lhs> - - <rhs>[a-zA-Z0-9]* <lineannotation>In real documents this is too - restrictive!</lineannotation></rhs> - </production> - </productionset> - - <para>We may as well supply a graphical representation:</para> - - <figure xml:id="extendContModelGraph"> - <title>Graphical representation of the extended <code>content</code> - model.</title> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/contentmixed.fig"/> - </imageobject> - </mediaobject> - </figure> - - <para>In comparison to our informal description of memo documents a - schema offers an added value: The grammar is machine readable and may - thus become input to a parser which in turn gets enabled to check - whether an XML document obeys the constraints being imposed. So the - parser must be instructed to use a schema in addition to the XML - document in question. For this purpose an XML document may define a - reference to a schema:</para> - - <figure xml:id="memo_external_dtd"> - <title>A memo document instance holding a reference to a document - external schema.</title> - - <programlisting language="none"><memo <co - xml:id="memo_external_dtd_top_element"/> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + <calloutlist> + <callout arearefs="memodtd_memodef"> + <para>A <tag class="element">memo</tag> consists of a sender, at + least one recipient, a subject and content.</para> + </callout> + + <callout arearefs="memodtd_memo_attribs"> + <para>A <tag class="element">memo</tag> has got one required + attribute <varname>date</varname> and an optional attribute + <varname>priority</varname> being restricted to the three allowed + values <tag class="attvalue">low</tag>, <tag + class="attvalue">medium</tag> and <tag class="attvalue">high</tag> + being defined by a separate <tag + class="starttag">xs:simpleType</tag> directive. Consider a similar + example being inspired from Xhtml:</para> + + <figure xml:id="sda1FigSchemaAttribDef"> + <title>Attribute schema definition example</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/attribInElement.fig"/> + </imageobject> + </mediaobject> + </figure> + </callout> + + <callout arearefs="memodtd_elem_from"> + <para>A <tag class="starttag">from</tag> element consists of + ordinary text. This disallows XML markup. For example the + <quote>&</quote> within <code><from>Smith & + partner</from></code> is disallowed since XML uses the + ampersand to denote the beginning of an entity like <tag + class="genentity">auml</tag> for the German a-umlaut (ä). The + correct form is <code><from>Smith &amp; + partner</from></code> using the predefined entity <tag + class="genentity">amp</tag> as an escape sequence.</para> + + <para><code>type="xs:string"</code> is a built in XML Schema type + representing a restricted version of ordinary strings. Without + digging into details a <code>xs:string</code> string must not + contain any markup code like e.g. <tag + class="starttag">msqrt</tag>. This ensures that a string does not + interfere with the document's XML markup.</para> + </callout> + </calloutlist> + </figure> + + <para>We notice our schema's syntax itself is an XML document.</para> + + <para>From the viewpoint of software modeling an XML Schema instance is + a <emphasis>schema</emphasis> describing the syntax of a class of XML + document instances adhering to it. In the context of XML technologies + <link xlink:href="http://www.w3.org/XML/Schema">XML Schema</link> is one + of several language alternatives which allow for XML document structure + descriptions.</para> + + <para>Readers being familiar with <abbrev + xlink:href="http://en.wikipedia.org/wiki/Backus-Naur_form">BNF</abbrev> + or <abbrev + xlink:href="http://en.wikipedia.org/wiki/Extended_Backus_Naur_form">EBNF</abbrev> + will be able to understand the grammatical rules being expressed + here.</para> + + <productionset> + <title>A message of type <tag class="starttag">memo</tag></title> + + <production xml:id="memo.ebnf.memo"> + <lhs>Memo Message</lhs> + + <rhs>'<memo>' <nonterminal + def="#memo.ebnf.sender">Sender</nonterminal> [<nonterminal + def="#memo.ebnf.recipient">Recipient</nonterminal>]+ <nonterminal + def="#memo.ebnf.subject">Subject</nonterminal> <nonterminal + def="#memo.ebnf.content">Content</nonterminal> '</memo>'</rhs> + </production> + + <production xml:id="memo.ebnf.sender"> + <lhs>Sender</lhs> + + <rhs>'<from>' <nonterminal def="#memo.ebnf.text"> Text + </nonterminal> '</from>'</rhs> + </production> + + <production xml:id="memo.ebnf.recipient"> + <lhs>Recipient</lhs> + + <rhs>'<to>' <nonterminal def="#memo.ebnf.text"> Text + </nonterminal> '</to>'</rhs> + </production> + + <production xml:id="memo.ebnf.subject"> + <lhs>Subject</lhs> + + <rhs>'<subject>' <nonterminal def="#memo.ebnf.text"> Text + </nonterminal> '</subject>'</rhs> + </production> + + <production xml:id="memo.ebnf.content"> + <lhs>Content</lhs> + + <rhs>'<content>' <nonterminal def="#memo.ebnf.text"> Text + </nonterminal> '</content>'</rhs> + </production> + + <production xml:id="memo.ebnf.text"> + <lhs>Text</lhs> + + <rhs>[a-zA-Z0-9]* <lineannotation>In real documents this is too + restrictive!</lineannotation></rhs> + </production> + </productionset> + + <para>We may as well supply a graphical representation:</para> + + <figure xml:id="extendContModelGraph"> + <title>Graphical representation of the extended <code>content</code> + model.</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/contentmixed.fig"/> + </imageobject> + </mediaobject> + </figure> + + <para>In comparison to our informal description of memo documents a + schema offers an added value: The grammar is machine readable and may + thus become input to a parser which in turn gets enabled to check + whether an XML document obeys the constraints being imposed. So the + parser must be instructed to use a schema in addition to the XML + document in question. For this purpose an XML document may define a + reference to a schema:</para> + + <figure xml:id="memo_external_dtd"> + <title>A memo document instance holding a reference to a document + external schema.</title> + + <programlisting language="none"><memo <co + xml:id="memo_external_dtd_top_element"/> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="memo.xsd" <co - xml:id="memo_external_dtd_url"/> + xml:id="memo_external_dtd_url"/> date="2014-09-24" priority="high"> <from>M. Goik</from> <to>B. King</to> @@ -322,240 +331,237 @@ <content>Hi all, congratulations to your splendid party</content> </memo></programlisting> - <calloutlist> - <callout arearefs="memo_external_dtd_top_element"> - <para>The element <tag class="starttag">memo</tag> is chosen to - be the top (root) element of the document's tree. It must be - defined in our schema <filename>memo.xsd</filename>. This is - really a choice since an XML schema defines a - <emphasis>set</emphasis> of elements in - <emphasis>arbitrary</emphasis> order. There is no such rule as - <quote>define before use</quote>. So an XML schema does not tell - us which element has to appear on top of a document.</para> - - <para>Suppose a given XML schema offers both <tag - class="starttag">book</tag> and <tag - class="starttag">report</tag> elements. An XML author writing a - complex document will choose <tag class="starttag">book</tag> as - top level element rather than <tag class="starttag">report</tag> - being more appropriate for a small piece of documentation. - Consequently it is an XML authors <emphasis>choice</emphasis> - which of the elements being defined in a schema shall appear as - <emphasis>the</emphasis> top level element</para> - </callout> - - <callout arearefs="memo_external_dtd_url"> - <para>The address of the schema's rule set. In the given example - it is just a filename but it may as well be an <link - xlink:href="http://www.w3.org/Addressing">URL</link> of type - <abbrev - xlink:href="http://en.wikipedia.org/wiki/File_Transfer_Protocol">ftp</abbrev>, - <abbrev xlink:href="http://www.w3.org/Protocols">http</abbrev> - and so on, see <xref linkend="memoDtdOnFtp"/>.</para> - </callout> - </calloutlist> - </figure> - - <para>In presence of a schema parsing a document is actually a two - step process: First the parser will check the document for well - -formedness. Then the parser will read the referenced schema - <filename>memo.xsd</filename> and check the document for the - additional constraints being defined within.</para> - - <para>In the current example both the schema and the XML memo document - reside as text files in a common file system folder. For general use a - schema is usually kept at a centralized location. The attribute - <varname>xsi:noNamespaceSchemaLocation</varname> value is actually a - <emphasis>U</emphasis><foreignphrase>niform</foreignphrase> - <emphasis>R</emphasis><foreignphrase>esource</foreignphrase> - <emphasis>L</emphasis><foreignphrase>ocator</foreignphrase> <link - xlink:href="http://www.w3.org/Addressing">(URL)</link>. Thus our - <filename>memo.xsd</filename> may also be supplied as a <abbrev - xlink:href="http://www.w3.org/Protocols">http</abbrev> or <abbrev - xlink:href="http://en.wikipedia.org/wiki/File_Transfer_Protocol">ftp</abbrev> - <link xlink:href="http://www.w3.org/Addressing">URL</link>:</para> - - <figure xml:id="memoDtdOnFtp"> - <title>A schema reference to a FTP server.</title> - - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <calloutlist> + <callout arearefs="memo_external_dtd_top_element"> + <para>The element <tag class="starttag">memo</tag> is chosen to be + the top (root) element of the document's tree. It must be defined + in our schema <filename>memo.xsd</filename>. This is really a + choice since an XML schema defines a <emphasis>set</emphasis> of + elements in <emphasis>arbitrary</emphasis> order. There is no such + rule as <quote>define before use</quote>. So an XML schema does + not tell us which element has to appear on top of a + document.</para> + + <para>Suppose a given XML schema offers both <tag + class="starttag">book</tag> and <tag class="starttag">report</tag> + elements. An XML author writing a complex document will choose + <tag class="starttag">book</tag> as top level element rather than + <tag class="starttag">report</tag> being more appropriate for a + small piece of documentation. Consequently it is an XML authors + <emphasis>choice</emphasis> which of the elements being defined in + a schema shall appear as <emphasis>the</emphasis> top level + element</para> + </callout> + + <callout arearefs="memo_external_dtd_url"> + <para>The address of the schema's rule set. In the given example + it is just a filename but it may as well be an <link + xlink:href="http://www.w3.org/Addressing">URL</link> of type + <abbrev + xlink:href="http://en.wikipedia.org/wiki/File_Transfer_Protocol">ftp</abbrev>, + <abbrev xlink:href="http://www.w3.org/Protocols">http</abbrev> and + so on, see <xref linkend="memoDtdOnFtp"/>.</para> + </callout> + </calloutlist> + </figure> + + <para>In presence of a schema parsing a document is actually a two step + process: First the parser will check the document for well -formedness. + Then the parser will read the referenced schema + <filename>memo.xsd</filename> and check the document for the additional + constraints being defined within.</para> + + <para>In the current example both the schema and the XML memo document + reside as text files in a common file system folder. For general use a + schema is usually kept at a centralized location. The attribute + <varname>xsi:noNamespaceSchemaLocation</varname> value is actually a + <emphasis>U</emphasis><foreignphrase>niform</foreignphrase> + <emphasis>R</emphasis><foreignphrase>esource</foreignphrase> + <emphasis>L</emphasis><foreignphrase>ocator</foreignphrase> <link + xlink:href="http://www.w3.org/Addressing">(URL)</link>. Thus our + <filename>memo.xsd</filename> may also be supplied as a <abbrev + xlink:href="http://www.w3.org/Protocols">http</abbrev> or <abbrev + xlink:href="http://en.wikipedia.org/wiki/File_Transfer_Protocol">ftp</abbrev> + <link xlink:href="http://www.w3.org/Addressing">URL</link>:</para> + + <figure xml:id="memoDtdOnFtp"> + <title>A schema reference to a FTP server.</title> + + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <memo ... xsi:noNamespaceSchemaLocation="https://someserver.org/memo.xsd"> <from>M. Goik</from> ... </memo></programlisting> - </figure> - - <para>Some terms are helpful in the context of schemas:</para> - - <variablelist> - <varlistentry> - <term>Validating / non-validating:</term> - - <listitem> - <para>A non-validating parser only checks a document for well- - formedness. If it also checks XML documents for conformance to - schema it is a <emphasis>validating</emphasis> parser.</para> - </listitem> - </varlistentry> - - <varlistentry> - <term>Valid / invalid documents:</term> - - <listitem> - <para>An XML document referencing a schema may either be valid - or invalid depending on its conformance to the schema in - question.</para> - </listitem> - </varlistentry> - - <varlistentry> - <term>Document instance:</term> - - <listitem> - <para>An XML memo document may conform to the <link - linkend="figure_memo_dtd">memo schema</link>. In this case we - call it a <emphasis>document instance</emphasis> of the memo - schema.</para> - - <para>This situation is quite similar as in typed programming - languages: A <xref linkend="glo_Java"/> - <code>class</code> declaration is a blueprint for the <xref linkend="glo_Java"/> runtime - system to construct <xref linkend="glo_Java"/> objects - in memory. This is done by e.g. a statement<code> String name = - new String();</code>. The identifier <code>name</code> will hold - a reference to an <emphasis>instance of class String</emphasis>. - So in a <xref linkend="glo_Java"/> runtime - environment a class declaration plays the same role as a schema - declaration in XML. See also <xref - linkend="example_memoJavaClass"/>.</para> - </listitem> - </varlistentry> - </variablelist> - - <para>For further discussions it is very useful to clearly distinguish - element definitions in a schema from their - <emphasis>realizations</emphasis> in a corresponding document - instance: Our memo schema defines an element <tag - class="starttag">from</tag> to be of content <type>xs:string</type>. - According to the schema at least one <tag class="starttag">from</tag> - clause must appear in a valid (conforming) document instance . If we - were talking about HTML document instances we would prefer to talk - about a <tag class="starttag">from</tag> <emphasis>tag</emphasis> - rather than a <tag class="starttag">from</tag> - <emphasis>element</emphasis>.</para> - - <para>In this document we will use the term <emphasis>element - type</emphasis> to denote an <code><xs:element ...</code> - definition in a schema. Thus we will talk about an element type <tag - class="element">subject</tag> being defined in - <filename>memo.xsd</filename>.</para> - - <para>An element type being defined in a <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev> - may have document instances as realizations. For example the document - instance shown in <xref linkend="memo_external_dtd"/> has two - <emphasis>nodes</emphasis> of element type <tag - class="element">to</tag>. Thus we say that the document instance - contains two <emphasis>element nodes</emphasis> of type <tag - class="element">to</tag>. We will frequently abbreviate this by saying - the instance contains to <tag class="starttag">from</tag> element - nodes. And we may even omit the term <emphasis>nodes</emphasis> and - simply talk about two <tag class="starttag">from</tag> elements. But - the careful reader should always distinguish between a single type - <code>foo</code> being defined in a <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev> - and the possibly empty set of <tag class="starttag">foo</tag> nodes - appearing in valid document instances.</para> - - <para><abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">Schema</abbrev>'s - appear on top of well-formed XML documents:</para> - - <figure xml:id="wellformedandvalid"> - <title>Well-formed and valid documents</title> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/wellformedandvalid.fig" scale="65"/> - </imageobject> - </mediaobject> - </figure> - - <qandaset defaultlabel="qanda" xml:id="example_memoTestValid"> - <title>Validation of memo document instances.</title> - - <qandadiv> - <qandaentry> - <question> - <para>Copy the two files <link - xlink:href="Ref/src/Memo.1/message.xml">message.xml</link> and - <link xlink:href="Ref/src/Memo.1/memo.xsd">memo.xsd</link> - into your eclipse project. Use the Oxygen XML plug in to check - if the document is valid. Then subsequently do and undo the - following changes each time checking the document for - validity:</para> - - <itemizedlist> - <listitem> - <para>Omit the <tag class="starttag">from</tag> - element.</para> - </listitem> - - <listitem> - <para>Change the order of the two sub elements <tag - class="starttag">subject</tag> and <tag - class="starttag">content</tag>.</para> - </listitem> - - <listitem> - <para>Erase the <varname>date</varname> attribute and its - value.</para> - </listitem> - - <listitem> - <para>Erase the <varname>priority</varname> attribute and - its value.</para> - </listitem> - </itemizedlist> - - <para>What do you observe?</para> - </question> - - <answer> - <para>The <tag class="attribute">priority</tag> attribute is - declared as <code>optional</code> and may thus be omitted. - Erasing the <tag class="attribute">priority</tag> attribute - thus leaves the document in a valid state. The remaining three - edit actions yield an invalid document instance.</para> - </answer> - </qandaentry> - - <qandaentry xml:id="example_memoJavaClass"> - <question> - <label>A memo implementation sketch in Java</label> - - <para>The aim of this exercise is to clarify the (abstract) - relation between XML <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and sets of <xref linkend="glo_Java"/> - classes rather then building a running application. We want to - model the <link xlink:href="Ref/src/Memo.1/memo.xsd">memo - schema</link> as a set of <xref linkend="glo_Java"/> - classes.</para> - </question> - - <answer> - <para>The XML attributes <tag class="attribute">date</tag> and - <tag class="attribute">priority</tag> can be mapped as <xref linkend="glo_Java"/> - attributes. The same applies for the Memo elements <tag - class="element">from</tag>, <tag class="element">subject</tag> - and <tag class="element">content</tag> which may be - implemented as simple Strings or alternatively as separate - Classes wrapping the String content. The latter method of - implementation should be preferred if the Memo schema is - expected to grow in complexity. A simple sketch reads:</para> - - <programlisting language="none">import java.util.Date; + </figure> + + <para>Some terms are helpful in the context of schemas:</para> + + <variablelist> + <varlistentry> + <term>Validating / non-validating:</term> + + <listitem> + <para>A non-validating parser only checks a document for well- + formedness. If it also checks XML documents for conformance to + schema it is a <emphasis>validating</emphasis> parser.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term>Valid / invalid documents:</term> + + <listitem> + <para>An XML document referencing a schema may either be valid or + invalid depending on its conformance to the schema in + question.</para> + </listitem> + </varlistentry> + + <varlistentry> + <term>Document instance:</term> + + <listitem> + <para>An XML memo document may conform to the <link + linkend="figure_memo_dtd">memo schema</link>. In this case we call + it a <emphasis>document instance</emphasis> of the memo + schema.</para> + + <para>This situation is quite similar as in typed programming + languages: A <xref linkend="glo_Java"/> <code>class</code> + declaration is a blueprint for the <xref linkend="glo_Java"/> + runtime system to construct <xref linkend="glo_Java"/> objects in + memory. This is done by e.g. a statement<code> String name = new + String();</code>. The identifier <code>name</code> will hold a + reference to an <emphasis>instance of class String</emphasis>. So + in a <xref linkend="glo_Java"/> runtime environment a class + declaration plays the same role as a schema declaration in XML. + See also <xref linkend="example_memoJavaClass"/>.</para> + </listitem> + </varlistentry> + </variablelist> + + <para>For further discussions it is very useful to clearly distinguish + element definitions in a schema from their + <emphasis>realizations</emphasis> in a corresponding document instance: + Our memo schema defines an element <tag class="starttag">from</tag> to + be of content <type>xs:string</type>. According to the schema at least + one <tag class="starttag">from</tag> clause must appear in a valid + (conforming) document instance . If we were talking about HTML document + instances we would prefer to talk about a <tag + class="starttag">from</tag> <emphasis>tag</emphasis> rather than a <tag + class="starttag">from</tag> <emphasis>element</emphasis>.</para> + + <para>In this document we will use the term <emphasis>element + type</emphasis> to denote an <code><xs:element ...</code> definition + in a schema. Thus we will talk about an element type <tag + class="element">subject</tag> being defined in + <filename>memo.xsd</filename>.</para> + + <para>An element type being defined in a <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev> + may have document instances as realizations. For example the document + instance shown in <xref linkend="memo_external_dtd"/> has two + <emphasis>nodes</emphasis> of element type <tag + class="element">to</tag>. Thus we say that the document instance + contains two <emphasis>element nodes</emphasis> of type <tag + class="element">to</tag>. We will frequently abbreviate this by saying + the instance contains to <tag class="starttag">from</tag> element nodes. + And we may even omit the term <emphasis>nodes</emphasis> and simply talk + about two <tag class="starttag">from</tag> elements. But the careful + reader should always distinguish between a single type <code>foo</code> + being defined in a <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev> + and the possibly empty set of <tag class="starttag">foo</tag> nodes + appearing in valid document instances.</para> + + <para><abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">Schema</abbrev>'s + appear on top of well-formed XML documents:</para> + + <figure xml:id="wellformedandvalid"> + <title>Well-formed and valid documents</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/wellformedandvalid.fig" scale="65"/> + </imageobject> + </mediaobject> + </figure> + + <qandaset defaultlabel="qanda" xml:id="example_memoTestValid"> + <title>Validation of memo document instances.</title> + + <qandadiv> + <qandaentry> + <question> + <para>Copy the two files <link + xlink:href="Ref/src/Memo.1/message.xml">message.xml</link> and + <link xlink:href="Ref/src/Memo.1/memo.xsd">memo.xsd</link> into + your eclipse project. Use the Oxygen XML plug in to check if the + document is valid. Then subsequently do and undo the following + changes each time checking the document for validity:</para> + + <itemizedlist> + <listitem> + <para>Omit the <tag class="starttag">from</tag> + element.</para> + </listitem> + + <listitem> + <para>Change the order of the two sub elements <tag + class="starttag">subject</tag> and <tag + class="starttag">content</tag>.</para> + </listitem> + + <listitem> + <para>Erase the <varname>date</varname> attribute and its + value.</para> + </listitem> + + <listitem> + <para>Erase the <varname>priority</varname> attribute and + its value.</para> + </listitem> + </itemizedlist> + + <para>What do you observe?</para> + </question> + + <answer> + <para>The <tag class="attribute">priority</tag> attribute is + declared as <code>optional</code> and may thus be omitted. + Erasing the <tag class="attribute">priority</tag> attribute thus + leaves the document in a valid state. The remaining three edit + actions yield an invalid document instance.</para> + </answer> + </qandaentry> + + <qandaentry xml:id="example_memoJavaClass"> + <question> + <label>A memo implementation sketch in Java</label> + + <para>The aim of this exercise is to clarify the (abstract) + relation between XML <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s + and sets of <xref linkend="glo_Java"/> classes rather then + building a running application. We want to model the <link + xlink:href="Ref/src/Memo.1/memo.xsd">memo schema</link> as a set + of <xref linkend="glo_Java"/> classes.</para> + </question> + + <answer> + <para>The XML attributes <tag class="attribute">date</tag> and + <tag class="attribute">priority</tag> can be mapped as <xref + linkend="glo_Java"/> attributes. The same applies for the Memo + elements <tag class="element">from</tag>, <tag + class="element">subject</tag> and <tag + class="element">content</tag> which may be implemented as simple + Strings or alternatively as separate Classes wrapping the String + content. The latter method of implementation should be preferred + if the Memo schema is expected to grow in complexity. A simple + sketch reads:</para> + + <programlisting language="none">import java.util.Date; import java.util.SortedSet; public class Memo { @@ -566,88 +572,92 @@ public class Memo { // Accessors not yet implemented }</programlisting> - <para>The only thing to note here is the implementation of the - <tag class="element">to</tag> element: We want to be able to - address a <emphasis>set</emphasis> of recipients. Thus we have - to disallow duplicates. Note that this is an - <emphasis>informal</emphasis> constraint not being handled by - our schema: A Memo document instance <emphasis>may</emphasis> - have duplicate content in <tag class="starttag">to</tag> - nodes. This is a weakness of <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>s: - We are unable to impose uniqueness constraints on the content - of partial sets of document nodes.</para> - - <para>On the other hand our set of recipients has to be - ordered: In a XML document instance the order of <tag - class="starttag">to</tag> nodes is important and has to be - preserved in a <xref linkend="glo_Java"/> - representation. Thus we choose an - <classname>java.util.SortedSet</classname> parametrized with - String type to fulfill both requirements.</para> - - <para>Our schema defines:</para> - - <programlisting language="none"><!ATTLIST memo ... priority (low|medium|high) #IMPLIED></programlisting> - - <para>Starting from <xref linkend="glo_Java"/> 1.5 we - may implement this constraint by a type safe enumeration in a - file <filename>Priority.java</filename>:</para> - - <programlisting language="none">public enum Priority{low, standard, high};</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - - <para>In the following chapters we will extend the memo document type - (<code><!DOCTYPE memo ... ></code>) to demonstrate various - concepts of <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and other XML related standards. In parallel a series of exercises - deals with building a schema usable to edit books. This schema gets - extended as our knowledge about XML advances. We start with an initial - exercise:</para> - - <qandaset defaultlabel="qanda" xml:id="example_bookDtd"> - <title>A schema for editing books</title> - - <qandadiv> - <qandaentry> - <question> - <para>Write a schema describing book document instances with - the following features:</para> - - <itemizedlist> - <listitem> - <para>A book shall have a title to describe the book - itself.</para> - </listitem> - - <listitem> - <para>A book shall have at least one but possibly a - sequence of chapters.</para> - </listitem> - - <listitem> - <para>Each chapter shall have a title and at least one - paragraph.</para> - </listitem> - - <listitem> - <para>The titles and paragraphs shall consist of ordinary - text.</para> - </listitem> - </itemizedlist> - </question> - - <answer> - <para>A possible schema looks like:</para> - - <figure xml:id="figure_book.dtd_v1"> - <title>A first schema version for book documents</title> + <para>The only thing to note here is the implementation of the + <tag class="element">to</tag> element: We want to be able to + address a <emphasis>set</emphasis> of recipients. Thus we have + to disallow duplicates. Note that this is an + <emphasis>informal</emphasis> constraint not being handled by + our schema: A Memo document instance <emphasis>may</emphasis> + have duplicate content in <tag class="starttag">to</tag> nodes. + This is a weakness of <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>s: + We are unable to impose uniqueness constraints on the content of + partial sets of document nodes.</para> + + <para>On the other hand our set of recipients has to be ordered: + In a XML document instance the order of <tag + class="starttag">to</tag> nodes is important and has to be + preserved in a <xref linkend="glo_Java"/> representation. Thus + we choose an <classname>java.util.SortedSet</classname> + parametrized with String type to fulfill both + requirements.</para> + + <para>Our schema defines:</para> + + <programlisting language="none"><xs:simpleType name="Priority"> + <xs:restriction base="xs:string"> + <xs:enumeration value="low"/> + <xs:enumeration value="medium"/> + <xs:enumeration value="high"/> + </xs:restriction> + </xs:simpleType></programlisting> + + <para>Starting from <xref linkend="glo_Java"/> 1.5 we may + implement this constraint by a type safe enumeration:</para> + + <programlisting language="none">public enum Priority {low, standard, high};</programlisting> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + + <para>In the following chapters we will extend the memo document schema + to demonstrate various concepts of <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s + and other XML related standards. In parallel a series of exercises deals + with building a schema usable to edit books. This schema gets extended + as our knowledge about XML advances. We start with an initial + exercise:</para> + + <qandaset defaultlabel="qanda" xml:id="example_bookDtd"> + <title>A schema for editing books</title> + + <qandadiv> + <qandaentry> + <question> + <para>Write a schema describing book document instances with the + following features:</para> + + <itemizedlist> + <listitem> + <para>A book shall have a title to describe the book + itself.</para> + </listitem> + + <listitem> + <para>A book shall have at least one but possibly a sequence + of chapters.</para> + </listitem> + + <listitem> + <para>Each chapter shall have a title and at least one + paragraph.</para> + </listitem> + + <listitem> + <para>The titles and paragraphs shall consist of ordinary + text.</para> + </listitem> + </itemizedlist> + </question> + + <answer> + <para>A possible schema looks like:</para> + + <figure xml:id="figure_book.dtd_v1"> + <title>A first schema version for book documents</title> - <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -673,12 +683,12 @@ public class Memo { <xs:element name="para" type="xs:string"/> </xs:schema></programlisting> - </figure> + </figure> - <para>We supply a valid document instance:</para> + <para>We supply a valid document instance:</para> - <informalfigure xml:id="bookInitialInstance"> - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <informalfigure xml:id="bookInitialInstance"> + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="book.xsd"> <title>Introduction to Java</title> @@ -696,67 +706,67 @@ public class Memo { <para>This is especially useful for framework authors.</para> </chapter> </book></programlisting> - </informalfigure> - - <para>.</para> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="dtdVsSqlDdl"> - <title>Relating <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and <acronym - xlink:href="http://en.wikipedia.org/wiki/Sql">SQL</acronym> - <abbrev - xlink:href="http://en.wikipedia.org/wiki/Data_definition_language">DDL</abbrev></title> + </informalfigure> - <para>XML <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and <acronym - xlink:href="http://en.wikipedia.org/wiki/Sql">SQL</acronym> - <abbrev - xlink:href="http://en.wikipedia.org/wiki/Data_definition_language">DDL</abbrev> - are related: They both describe data models and thus integrity - constraints. We consider a simple invoice example:</para> - - <figure xml:id="invoiceIntegrity"> - <title>Invoice integrity constraints</title> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/invoicedata.fig" scale="65"/> - </imageobject> - </mediaobject> - </figure> - - <para>A relational implementation may look like:</para> - - <figure xml:id="invoiceSqlDdl"> - <title>Relational implementation</title> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/invoicedataimplement.fig" scale="65"/> - </imageobject> - </mediaobject> - </figure> - - <qandaset defaultlabel="qanda" xml:id="qandaInvoiceSchema"> - <title>An XML schema representing invoices</title> - - <qandadiv> - <qandaentry> - <question> - <para>Represent the relational schema being described in <xref - linkend="invoiceSqlDdl"/> by an XML Schema and provide an - appropriate instance example.</para> - </question> - - <answer> - <para>A possible schema implementation:</para> + <para>.</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> - <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + <section xml:id="dtdVsSqlDdl"> + <title>Relating <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s + and <acronym xlink:href="http://en.wikipedia.org/wiki/Sql">SQL</acronym> + - <abbrev + xlink:href="http://en.wikipedia.org/wiki/Data_definition_language">DDL</abbrev></title> + + <para>XML <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s + and <acronym xlink:href="http://en.wikipedia.org/wiki/Sql">SQL</acronym> + - <abbrev + xlink:href="http://en.wikipedia.org/wiki/Data_definition_language">DDL</abbrev> + are related: They both describe data models and thus integrity + constraints. We consider a simple invoice example:</para> + + <figure xml:id="invoiceIntegrity"> + <title>Invoice integrity constraints</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/invoicedata.fig" scale="65"/> + </imageobject> + </mediaobject> + </figure> + + <para>A relational implementation may look like:</para> + + <figure xml:id="invoiceSqlDdl"> + <title>Relational implementation</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/invoicedataimplement.fig" scale="65"/> + </imageobject> + </mediaobject> + </figure> + + <qandaset defaultlabel="qanda" xml:id="qandaInvoiceSchema"> + <title>An XML schema representing invoices</title> + + <qandadiv> + <qandaentry> + <question> + <para>Represent the relational schema being described in <xref + linkend="invoiceSqlDdl"/> by an XML Schema and provide an + appropriate instance example.</para> + </question> + + <answer> + <para>A possible schema implementation:</para> + + <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -814,9 +824,9 @@ public class Memo { </xs:schema></programlisting> - <para>An example data set:</para> + <para>An example data set:</para> - <programlisting language="none"><data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + <programlisting language="none"><data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="invoice.xsd"> <customer id="5"> <name>Clarke Jefferson</name> @@ -827,68 +837,68 @@ public class Memo { <status>due</status> </invoice> </data></programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> - <section xml:id="airlineXsd"> - <title>The airline example revisited</title> + <section xml:id="airlineXsd"> + <title>The airline example revisited</title> - <qandaset defaultlabel="qanda" xml:id="qandaAirlineXsd"> - <title>Airline meta information by XML schema</title> + <qandaset defaultlabel="qanda" xml:id="qandaAirlineXsd"> + <title>Airline meta information by XML schema</title> - <qandadiv> - <qandaentry> - <question> - <para>Transform the relational schema from <xref - linkend="airlineRelationalSchema"/> into an XML schema and - supply some test data. In particular consider the following - constraints:</para> + <qandadiv> + <qandaentry> + <question> + <para>Transform the relational schema from <xref + linkend="airlineRelationalSchema"/> into an XML schema and + supply some test data. In particular consider the following + constraints:</para> - <itemizedlist> - <listitem> - <para>Data types</para> - - <itemizedlist> - <listitem> - <para><link - xlink:href="http://en.wikipedia.org/wiki/List_of_airline_codes">ICAO - airline designator</link></para> - </listitem> - - <listitem> - <para><link - xlink:href="http://en.wikipedia.org/wiki/International_Civil_Aviation_Organization_airport_code">ICAO - airport code</link></para> - </listitem> - </itemizedlist> - </listitem> + <itemizedlist> + <listitem> + <para>Data types</para> - <listitem> - <para>Primary / Unique key definitions</para> - </listitem> - - <listitem> - <para>Foreign key definitions</para> - </listitem> - - <listitem> - <para>CHECK constraint: Your XML schema will require <tag - class="starttag">xs:assert test="..." </tag> and thus XML - schema version 1.1. You may want to read about - co-occurrence constraints as being described in <link - xlink:href="http://www.ibm.com/developerworks/library/x-xml11pt2">Listing - 6. Assertion on complex type - @height < - @width</link>.</para> - </listitem> - </itemizedlist> - - <para>The following XML example instance may guide you towards - an <filename>airline.xsd</filename> schema:</para> + <itemizedlist> + <listitem> + <para><link + xlink:href="http://en.wikipedia.org/wiki/List_of_airline_codes">ICAO + airline designator</link></para> + </listitem> - <programlisting language="none"><top xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + <listitem> + <para><link + xlink:href="http://en.wikipedia.org/wiki/International_Civil_Aviation_Organization_airport_code">ICAO + airport code</link></para> + </listitem> + </itemizedlist> + </listitem> + + <listitem> + <para>Primary / Unique key definitions</para> + </listitem> + + <listitem> + <para>Foreign key definitions</para> + </listitem> + + <listitem> + <para>CHECK constraint: Your XML schema will require <tag + class="starttag">xs:assert test="..." </tag> and thus XML + schema version 1.1. You may want to read about co-occurrence + constraints as being described in <link + xlink:href="http://www.ibm.com/developerworks/library/x-xml11pt2">Listing + 6. Assertion on complex type - @height < + @width</link>.</para> + </listitem> + </itemizedlist> + + <para>The following XML example instance may guide you towards + an <filename>airline.xsd</filename> schema:</para> + + <programlisting language="none"><top xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="airline.xsd"> <airlines> <airline airlineCode="DLH" id="1"> @@ -915,26 +925,26 @@ public class Memo { </flights> </top></programlisting> - <para>Hints:</para> - - <itemizedlist> - <listitem> - <para>Identify all relational schema constraints from - solution of <xref linkend="airlineRelationalSchema"/> and - model them accordingly.</para> - </listitem> - - <listitem> - <para>The above example does not contain any constraint - violations. In order to test your schema for completeness - tinkering with primary key, unique and referencing - attribute values may be helpful.</para> - </listitem> - </itemizedlist> - </question> - - <answer> - <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + <para>Hints:</para> + + <itemizedlist> + <listitem> + <para>Identify all relational schema constraints from + solution of <xref linkend="airlineRelationalSchema"/> and + model them accordingly.</para> + </listitem> + + <listitem> + <para>The above example does not contain any constraint + violations. In order to test your schema for completeness + tinkering with primary key, unique and referencing attribute + values may be helpful.</para> + </listitem> + </itemizedlist> + </question> + + <answer> + <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.1"> @@ -1076,53 +1086,52 @@ public class Memo { </xs:element> </xs:schema></programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="xmlAndJava"> + <title>Relating <abbrev + xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s + and <xref linkend="glo_Java"/> class descriptions.</title> - <section xml:id="xmlAndJava"> - <title>Relating <abbrev + <para>We may also compare XML data constraints to <xref + linkend="glo_Java"/>. A <xref linkend="glo_Java"/> class declaration is + actually a blueprint for a <trademark + xlink:href="http://www.oracle.com/technetwork/java/javase">JRE</trademark> + to instantiate compatible objects. Likewise an XML schema restricts + well-formed documents:</para> + + <figure xml:id="fig_XmlAndJava"> + <title>XML <abbrev xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and <xref linkend="glo_Java"/> - class descriptions.</title> - - <para>We may also compare XML data constraints to <xref linkend="glo_Java"/>. A <xref linkend="glo_Java"/> class - declaration is actually a blueprint for a <trademark - xlink:href="http://www.oracle.com/technetwork/java/javase">JRE</trademark> - to instantiate compatible objects. Likewise an XML schema restricts - well-formed documents:</para> - - <figure xml:id="fig_XmlAndJava"> - <title>XML <abbrev - xlink:href="http://en.wikipedia.org/wiki/Document_Type_Declaration">schema</abbrev>'s - and <xref linkend="glo_Java"/> - class declarations.</title> - - <mediaobject> - <imageobject> - <imagedata fileref="Ref/Fig/xmlattribandjava.fig" scale="65"/> - </imageobject> - </mediaobject> - </figure> - </section> + and <xref linkend="glo_Java"/> class declarations.</title> + + <mediaobject> + <imageobject> + <imagedata fileref="Ref/Fig/xmlattribandjava.fig" scale="65"/> + </imageobject> + </mediaobject> + </figure> + </section> - <section xml:id="xmlSchemaExercise"> - <title>XML schema exercises</title> + <section xml:id="xmlSchemaExercise"> + <title>XML schema exercises</title> - <section xml:id="sectSchemaProductCatalog"> - <title>A product catalog</title> + <section xml:id="sectSchemaProductCatalog"> + <title>A product catalog</title> - <qandaset defaultlabel="qanda" xml:id="quandaProductCatalog"> - <title>Product catalog schema</title> + <qandaset defaultlabel="qanda" xml:id="quandaProductCatalog"> + <title>Product catalog schema</title> - <qandadiv> - <qandaentry> - <question> - <para>Consider the following product catalog example:</para> + <qandadiv> + <qandaentry> + <question> + <para>Consider the following product catalog example:</para> - <programlisting language="none"><catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + <programlisting language="none"><catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog.xsd"> <title>Outdoor products</title> <introduction> @@ -1146,53 +1155,51 @@ public class Memo { </product> </catalog></programlisting> - <para>As you may have inferred the following rules shall - apply for arbitrary catalog documents:</para> + <para>As you may have inferred the following rules shall apply + for arbitrary catalog documents:</para> - <itemizedlist> - <listitem> - <para>Each <tag class="starttag">catalog</tag> shall - have exactly one <tag class="starttag">title</tag> and - <tag class="starttag">introduction</tag> element.</para> - </listitem> + <itemizedlist> + <listitem> + <para>Each <tag class="starttag">catalog</tag> shall have + exactly one <tag class="starttag">title</tag> and <tag + class="starttag">introduction</tag> element.</para> + </listitem> - <listitem> - <para><tag class="starttag">introduction</tag> and <tag - class="starttag">description</tag> shall have at least - one <tag class="starttag">para</tag> child.</para> - </listitem> + <listitem> + <para><tag class="starttag">introduction</tag> and <tag + class="starttag">description</tag> shall have at least one + <tag class="starttag">para</tag> child.</para> + </listitem> - <listitem> - <para>Each <tag class="starttag">catalog</tag> shall - have at least one <tag - class="starttag">product</tag>.</para> - </listitem> + <listitem> + <para>Each <tag class="starttag">catalog</tag> shall have + at least one <tag class="starttag">product</tag>.</para> + </listitem> - <listitem> - <para>Each <tag class="starttag">product</tag> shall - have exactly one <tag class="starttag">title</tag> and - at least one <tag class="starttag">para</tag> child - element.</para> - </listitem> + <listitem> + <para>Each <tag class="starttag">product</tag> shall have + exactly one <tag class="starttag">title</tag> and at least + one <tag class="starttag">para</tag> child element.</para> + </listitem> - <listitem> - <para>The required <code>id</code> attribute shall not - contain whitespace and be unique with respect to all - <tag class="starttag">product</tag> elements.</para> - </listitem> + <listitem> + <para>The required <code>id</code> attribute shall not + contain whitespace and be unique with respect to all <tag + class="starttag">product</tag> elements.</para> + </listitem> - <listitem> - <para>The attribute price shall represent money amounts - and be optional.</para> - </listitem> - </itemizedlist> + <listitem> + <para>The attribute price shall represent money amounts + and be optional.</para> + </listitem> + </itemizedlist> - <para>Provide a suitable <filename>catalog.xsd</filename> - schema.</para> - </question> + <para>Provide a suitable <filename>catalog.xsd</filename> + schema.</para> + </question> - <answer> - <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + <answer> + <programlisting language="none"><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -1241,56 +1248,55 @@ public class Memo { </xs:element> </xs:schema></programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="sectQandaBookV1"> - <title>Book like documents</title> - - <qandaset defaultlabel="qanda" xml:id="example_operatorprecedence"> - <title>Book documents with mixed content and itemized - lists</title> - - <qandadiv> - <qandaentry xml:id="example_book_v2"> - <question> - <para>Extend the first version of <link - linkend="example_bookDtd">book.xsd</link> to support the - following features:</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> - <itemizedlist> - <listitem> - <para>Within a <tag class="starttag">chapter</tag> node - <tag class="starttag">para</tag> and <tag - class="starttag">itemizedlist</tag> elements in - arbitrary order shall be allowed.</para> - </listitem> + <section xml:id="sectQandaBookV1"> + <title>Book like documents</title> - <listitem> - <para><tag class="starttag">itemizedlist</tag> nodes - shall contain at least one <tag - class="starttag">listitem</tag>.</para> - </listitem> + <qandaset defaultlabel="qanda" xml:id="example_operatorprecedence"> + <title>Book documents with mixed content and itemized lists</title> - <listitem> - <para><tag class="starttag">listitem</tag> nodes shall - be composed of one or more para or nested list item - elements.</para> - </listitem> + <qandadiv> + <qandaentry xml:id="example_book_v2"> + <question> + <para>Extend the first version of <link + linkend="example_bookDtd">book.xsd</link> to support the + following features:</para> - <listitem> - <para>Within a <tag class="starttag">para</tag> we want - to be able to emphasize text passages.</para> - </listitem> - </itemizedlist> + <itemizedlist> + <listitem> + <para>Within a <tag class="starttag">chapter</tag> node + <tag class="starttag">para</tag> and <tag + class="starttag">itemizedlist</tag> elements in arbitrary + order shall be allowed.</para> + </listitem> + + <listitem> + <para><tag class="starttag">itemizedlist</tag> nodes shall + contain at least one <tag + class="starttag">listitem</tag>.</para> + </listitem> - <para>The following sample document instance shall be - valid:</para> + <listitem> + <para><tag class="starttag">listitem</tag> nodes shall be + composed of one or more para or nested list item + elements.</para> + </listitem> - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <listitem> + <para>Within a <tag class="starttag">para</tag> we want to + be able to emphasize text passages.</para> + </listitem> + </itemizedlist> + + <para>The following sample document instance shall be + valid:</para> + + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="catalog.xsd"> <title>Introduction to Java</title> @@ -1311,15 +1317,15 @@ public class Memo { </itemizedlist> </chapter> </book></programlisting> - </question> + </question> - <answer> - <para>An extended schema looks like:</para> + <answer> + <para>An extended schema looks like:</para> - <figure xml:id="paraListEmphasize"> - <title>Version 2 of book.xsd</title> + <figure xml:id="paraListEmphasize"> + <title>Version 2 of book.xsd</title> - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -1378,7 +1384,7 @@ public class Memo { <xs:element name="para"> <xs:complexType mixed="true"> <co - xml:id="figure_book.dtd_v2_para"/> + xml:id="figure_book.dtd_v2_para"/> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="emphasis"/> <xs:element ref="link"/> @@ -1391,7 +1397,7 @@ public class Memo { <xs:complexType> <xs:sequence> <xs:element ref="listitem" minOccurs="1" <co - xml:id="figure_book.dtd_v2_itemizedlist"/> maxOccurs="unbounded"/> + xml:id="figure_book.dtd_v2_itemizedlist"/> maxOccurs="unbounded"/> </xs:sequence> <xs:attribute name="id" type="xs:ID" use="optional"/> </xs:complexType> @@ -1400,7 +1406,7 @@ public class Memo { <xs:element name="listitem"> <xs:complexType> <xs:choice minOccurs="1" maxOccurs="unbounded"> <co - xml:id="figure_book.dtd_v2_listitem"/> + xml:id="figure_book.dtd_v2_listitem"/> <xs:element ref="para"/> <xs:element ref="itemizedlist"/> </xs:choice> @@ -1409,97 +1415,95 @@ public class Memo { </xs:schema></programlisting> - <caption> - <para>This allows emphasized text in <tag - class="starttag">para</tag> nodes and <tag - class="starttag">itemizedlists</tag>.</para> - </caption> - </figure> - - <calloutlist> - <callout arearefs="figure_book.dtd_v2_chapter"> - <para>We hook into <tag class="starttag">chapter</tag> - to allow arbitrary sequences of at least one <tag - class="starttag">para</tag> or <tag - class="starttag">itemizedlist</tag> element node.</para> - </callout> - - <callout arearefs="figure_book.dtd_v2_para"> - <para><tag class="starttag">para</tag> nodes now allow - mixed content.</para> - </callout> - - <callout arearefs="figure_book.dtd_v2_itemizedlist"> - <para>An <tag class="starttag">itemizedlist</tag> - contains at least one list item.</para> - </callout> - - <callout arearefs="figure_book.dtd_v2_listitem"> - <para>A <tag class="starttag">listitem</tag> contains a - sequence of at least one <tag - class="starttag">para</tag> or <tag - class="starttag">itemizedlist</tag> child node. The - latter gives rise to nested lists. We find a similar - construct in HTML namely unnumbered lists defined by - <code><UL><LI>... </code>constructs.</para> - </callout> - </calloutlist> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="sectQandaBookLang"> - <title>Allow different languages</title> - - <qandaset defaultlabel="qanda" xml:id="example_book.dtd_v3"> - <title>book.xsd and languages</title> - - <qandadiv> - <qandaentry> - <question> - <para>We want to extend our schema from <xref - linkend="example_book_v2"/> by allowing an author to define - the language to be used within the whole or parts of the - document in question. Add an attribute <code>lang</code> to - all relevant elements like e.g. <tag class="starttag">para - lang="es"</tag>. An XML editor may use this attribute to - activate corresponding dictionaries for spell - checking.</para> - - <para>The <code>lang</code> attribute shall be restricted to - the following values:</para> + <caption> + <para>This allows emphasized text in <tag + class="starttag">para</tag> nodes and <tag + class="starttag">itemizedlists</tag>.</para> + </caption> + </figure> - <itemizedlist> - <listitem> - <para><token>en</token></para> - </listitem> + <calloutlist> + <callout arearefs="figure_book.dtd_v2_chapter"> + <para>We hook into <tag class="starttag">chapter</tag> to + allow arbitrary sequences of at least one <tag + class="starttag">para</tag> or <tag + class="starttag">itemizedlist</tag> element node.</para> + </callout> + + <callout arearefs="figure_book.dtd_v2_para"> + <para><tag class="starttag">para</tag> nodes now allow + mixed content.</para> + </callout> + + <callout arearefs="figure_book.dtd_v2_itemizedlist"> + <para>An <tag class="starttag">itemizedlist</tag> contains + at least one list item.</para> + </callout> + + <callout arearefs="figure_book.dtd_v2_listitem"> + <para>A <tag class="starttag">listitem</tag> contains a + sequence of at least one <tag class="starttag">para</tag> + or <tag class="starttag">itemizedlist</tag> child node. + The latter gives rise to nested lists. We find a similar + construct in HTML namely unnumbered lists defined by + <code><UL><LI>... </code>constructs.</para> + </callout> + </calloutlist> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> - <listitem> - <para><token>fr</token></para> - </listitem> + <section xml:id="sectQandaBookLang"> + <title>Allow different languages</title> - <listitem> - <para><token>de</token></para> - </listitem> + <qandaset defaultlabel="qanda" xml:id="example_book.dtd_v3"> + <title>book.xsd and languages</title> - <listitem> - <para><token>it</token></para> - </listitem> + <qandadiv> + <qandaentry> + <question> + <para>We want to extend our schema from <xref + linkend="example_book_v2"/> by allowing an author to define + the language to be used within the whole or parts of the + document in question. Add an attribute <code>lang</code> to + all relevant elements like e.g. <tag class="starttag">para + lang="es"</tag>. An XML editor may use this attribute to + activate corresponding dictionaries for spell checking.</para> - <listitem> - <para><token>es</token></para> - </listitem> - </itemizedlist> - </question> + <para>The <code>lang</code> attribute shall be restricted to + the following values:</para> + + <itemizedlist> + <listitem> + <para><token>en</token></para> + </listitem> + + <listitem> + <para><token>fr</token></para> + </listitem> + + <listitem> + <para><token>de</token></para> + </listitem> + + <listitem> + <para><token>it</token></para> + </listitem> + + <listitem> + <para><token>es</token></para> + </listitem> + </itemizedlist> + </question> - <answer> - <para>We define a suitable <tag - class="starttag">xs:attribute</tag> type:</para> + <answer> + <para>We define a suitable <tag + class="starttag">xs:attribute</tag> type:</para> - <programlisting language="none"><xs:attribute <emphasis - role="bold">name="lang"</emphasis>> + <programlisting language="none"><xs:attribute <emphasis + role="bold">name="lang"</emphasis>> <xs:simpleType> <xs:restriction base="xs:string"> <xs:enumeration value="en"/> @@ -1511,10 +1515,10 @@ public class Memo { </xs:simpleType> </xs:attribute></programlisting> - <para>Than we add this attribute to our elements like <tag - class="starttag">chapter</tag> and others:</para> + <para>Than we add this attribute to our elements like <tag + class="starttag">chapter</tag> and others:</para> - <programlisting language="none"> <xs:element name="chapter"> + <programlisting language="none"> <xs:element name="chapter"> <xs:complexType> <xs:sequence> ... </xs:sequence> <xs:attribute <emphasis role="bold">ref="lang"</emphasis> use="optional"/> @@ -1522,177 +1526,176 @@ public class Memo { </xs:complexType> </xs:element></programlisting> - <para>This allows us to set a language on arbitrary - hierarchy level. But of course we may define it on top level - as well:</para> + <para>This allows us to set a language on arbitrary hierarchy + level. But of course we may define it on top level as + well:</para> - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <book ... lang="english"> <title>Introduction to Java</title> ...</programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="sectMixQuotes"> - <title>Mixing attribute quotes</title> - - <qandaset defaultlabel="qanda" xml:id="example_quotes"> - <title>Single and double quotes reconsidered</title> - - <qandadiv> - <qandaentry> - <question> - <para>We recall the problem of nested quotes yielding - non-well formed XML code:</para> - - <programlisting language="none"><img src="bold.gif" alt="We may use "quotes" here" /></programlisting> - - <para>The XML specification defines legal attribute value - definitions as:</para> - - <productionset> - <title><link - xlink:href="http://www.w3.org/TR/2008/REC-xml-20081126/#d0e888">Literals</link></title> - - <production xml:id="w3RecXml_NT-EntityValue"> - <lhs>EntityValue</lhs> - - <rhs>'"' ([^%&"] | <nonterminal - def="#w3RecXml_NT-PEReference">PEReference</nonterminal> - | <nonterminal - def="#w3RecXml_NT-Reference">Reference</nonterminal>)* - '"' | "'" ([^%&'] | <nonterminal - def="#w3RecXml_NT-PEReference">PEReference</nonterminal> - | <nonterminal - def="#w3RecXml_NT-Reference">Reference</nonterminal>)* - "'"</rhs> - </production> - - <production xml:id="w3RecXml_NT-AttValue"> - <lhs>AttValue</lhs> - - <rhs>'"' ([^<&"] | <nonterminal - def="#w3RecXml_NT-Reference">Reference</nonterminal>)* - '"' | "'" ([^<&'] | <nonterminal - def="#w3RecXml_NT-Reference">Reference</nonterminal>)* - "'"</rhs> - </production> - - <production xml:id="w3RecXml_NT-SystemLiteral"> - <lhs>SystemLiteral</lhs> - - <rhs>('"' [^"]* '"') | ("'" [^']* "'")</rhs> - </production> - - <production xml:id="w3RecXml_NT-PubidLiteral"> - <lhs>PubidLiteral</lhs> - - <rhs>'"' <nonterminal - def="#w3RecXml_NT-PubidChar">PubidChar</nonterminal>* - '"' | "'" (<nonterminal - def="#w3RecXml_NT-PubidChar">PubidChar</nonterminal> - - "'")* "'"</rhs> - </production> - - <production xml:id="w3RecXml_NT-PubidChar"> - <lhs>PubidChar</lhs> - - <rhs>#x20 | #xD | #xA | [a-zA-Z0-9] - | [-'()+,./:=?;!*#@$_%]</rhs> - </production> - </productionset> - - <para>Find out how it is possible to set the attribute <tag - class="attribute">alt</tag>'s value to the string <code>We - may use "quotes" here</code>.</para> - </question> - - <answer> - <para>The production rule for attribute values reads:</para> - - <productionset> - <productionrecap linkend="w3RecXml_NT-AttValue"/> - </productionset> - - <para>This allows us to use either of two alternatives to - delimit attribute values:</para> - - <glosslist> - <glossentry> - <glossterm><tag class="starttag">img ... - alt="..."/</tag></glossterm> - - <glossdef> - <para><emphasis>Validity constraint:</emphasis> do not - use <code>"</code> inside the value string.</para> - </glossdef> - </glossentry> - - <glossentry> - <glossterm><tag class="starttag">img ... - alt='...'/</tag></glossterm> - - <glossdef> - <para><emphasis>Validity constraint:</emphasis> do not - use <code>'</code> inside the value string.</para> - </glossdef> - </glossentry> - </glosslist> - - <para>We may take advantage of the second rule:</para> - - <programlisting language="none"><img src="bold.gif" alt='We may use "quotes" here' /></programlisting> - - <para>Notice that according to <xref - linkend="w3RecXml_NT-AttValue"/> the delimiting quotes must - not be mixed. The following code is thus not well - formed:</para> - - <programlisting language="none"><img src="bold.gif'/></programlisting> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> - - <section xml:id="qandasetInternalRef"> - <title>Internal references</title> - - <qandaset defaultlabel="qanda" xml:id="example_book.dtd_v5"> - <title>book.xsd and internal references</title> - - <qandadiv> - <qandaentry> - <question> - <para>We want to extend <xref - linkend="example_book.dtd_v3"/> schema to allow for document - internal references by:</para> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> - <itemizedlist> - <listitem> - <para>Allowing each <tag class="starttag">chapter</tag>, - <tag class="starttag">para</tag> and <tag - class="starttag">itemizedlist</tag> to become reference - targets.</para> - </listitem> + <section xml:id="sectMixQuotes"> + <title>Mixing attribute quotes</title> - <listitem> - <para>Extending the element <tag - class="element">para</tag>'s mixed content model by a - new element <tag class="element">link</tag> with an - attribute <tag class="attribute">linkend</tag> being a - reference to a target.</para> - </listitem> - </itemizedlist> - </question> + <qandaset defaultlabel="qanda" xml:id="example_quotes"> + <title>Single and double quotes reconsidered</title> - <answer> - <para>We extend our schema:</para> + <qandadiv> + <qandaentry> + <question> + <para>We recall the problem of nested quotes yielding non-well + formed XML code:</para> + + <programlisting language="none"><img src="bold.gif" alt="We may use "quotes" here" /></programlisting> + + <para>The XML specification defines legal attribute value + definitions as:</para> + + <productionset> + <title><link + xlink:href="http://www.w3.org/TR/2008/REC-xml-20081126/#d0e888">Literals</link></title> + + <production xml:id="w3RecXml_NT-EntityValue"> + <lhs>EntityValue</lhs> + + <rhs>'"' ([^%&"] | <nonterminal + def="#w3RecXml_NT-PEReference">PEReference</nonterminal> | + <nonterminal + def="#w3RecXml_NT-Reference">Reference</nonterminal>)* '"' + | "'" ([^%&'] | <nonterminal + def="#w3RecXml_NT-PEReference">PEReference</nonterminal> | + <nonterminal + def="#w3RecXml_NT-Reference">Reference</nonterminal>)* + "'"</rhs> + </production> + + <production xml:id="w3RecXml_NT-AttValue"> + <lhs>AttValue</lhs> + + <rhs>'"' ([^<&"] | <nonterminal + def="#w3RecXml_NT-Reference">Reference</nonterminal>)* '"' + | "'" ([^<&'] | <nonterminal + def="#w3RecXml_NT-Reference">Reference</nonterminal>)* + "'"</rhs> + </production> + + <production xml:id="w3RecXml_NT-SystemLiteral"> + <lhs>SystemLiteral</lhs> + + <rhs>('"' [^"]* '"') | ("'" [^']* "'")</rhs> + </production> + + <production xml:id="w3RecXml_NT-PubidLiteral"> + <lhs>PubidLiteral</lhs> + + <rhs>'"' <nonterminal + def="#w3RecXml_NT-PubidChar">PubidChar</nonterminal>* '"' + | "'" (<nonterminal + def="#w3RecXml_NT-PubidChar">PubidChar</nonterminal> - + "'")* "'"</rhs> + </production> + + <production xml:id="w3RecXml_NT-PubidChar"> + <lhs>PubidChar</lhs> + + <rhs>#x20 | #xD | #xA | [a-zA-Z0-9] + | [-'()+,./:=?;!*#@$_%]</rhs> + </production> + </productionset> + + <para>Find out how it is possible to set the attribute <tag + class="attribute">alt</tag>'s value to the string <code>We may + use "quotes" here</code>.</para> + </question> - <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> + <answer> + <para>The production rule for attribute values reads:</para> + + <productionset> + <productionrecap linkend="w3RecXml_NT-AttValue"/> + </productionset> + + <para>This allows us to use either of two alternatives to + delimit attribute values:</para> + + <glosslist> + <glossentry> + <glossterm><tag class="starttag">img ... + alt="..."/</tag></glossterm> + + <glossdef> + <para><emphasis>Validity constraint:</emphasis> do not + use <code>"</code> inside the value string.</para> + </glossdef> + </glossentry> + + <glossentry> + <glossterm><tag class="starttag">img ... + alt='...'/</tag></glossterm> + + <glossdef> + <para><emphasis>Validity constraint:</emphasis> do not + use <code>'</code> inside the value string.</para> + </glossdef> + </glossentry> + </glosslist> + + <para>We may take advantage of the second rule:</para> + + <programlisting language="none"><img src="bold.gif" alt='We may use "quotes" here' /></programlisting> + + <para>Notice that according to <xref + linkend="w3RecXml_NT-AttValue"/> the delimiting quotes must + not be mixed. The following code is thus not well + formed:</para> + + <programlisting language="none"><img src="bold.gif'/></programlisting> + </answer> + </qandaentry> + </qandadiv> + </qandaset> + </section> + + <section xml:id="qandasetInternalRef"> + <title>Internal references</title> + + <qandaset defaultlabel="qanda" xml:id="example_book.dtd_v5"> + <title>book.xsd and internal references</title> + + <qandadiv> + <qandaentry> + <question> + <para>We want to extend <xref linkend="example_book.dtd_v3"/> + schema to allow for document internal references by:</para> + + <itemizedlist> + <listitem> + <para>Allowing each <tag class="starttag">chapter</tag>, + <tag class="starttag">para</tag> and <tag + class="starttag">itemizedlist</tag> to become reference + targets.</para> + </listitem> + + <listitem> + <para>Extending the element <tag + class="element">para</tag>'s mixed content model by a new + element <tag class="element">link</tag> with an attribute + <tag class="attribute">linkend</tag> being a reference to + a target.</para> + </listitem> + </itemizedlist> + </question> + + <answer> + <para>We extend our schema:</para> + + <programlisting language="none"><?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.0" vc:maxVersion="1.1"> @@ -1721,9 +1724,9 @@ public class Memo { <xs:element name="title" type="xs:string"/> <xs:element name="link"> <xs:complexType mixed="true"> <co - xml:id="progamlisting_book_v5_link"/> + xml:id="progamlisting_book_v5_link"/> <xs:attribute name="linkend" <co - xml:id="progamlisting_book_v5_link_linkend"/> type="xs:IDREF" use="required"/> + xml:id="progamlisting_book_v5_link_linkend"/> type="xs:IDREF" use="required"/> </xs:complexType> </xs:element> @@ -1750,21 +1753,21 @@ public class Memo { </xs:sequence> <xs:attribute ref="lang" use="optional"/> <xs:attribute name="id" <co - xml:id="progamlisting_book_v5_chapter_id"/> type="xs:ID" use="optional"/> + xml:id="progamlisting_book_v5_chapter_id"/> type="xs:ID" use="optional"/> <xs:attribute ref="xml:base"/> <!-- This allows for <xi:include ...> --> </xs:complexType> </xs:element> <xs:element name="para"> <xs:complexType mixed="true"> <co - xml:id="progamlisting_book_v5_mixed_link"/> + xml:id="progamlisting_book_v5_mixed_link"/> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element ref="emphasis"/> <xs:element ref="link"/> </xs:choice> <xs:attribute ref="lang" use="optional"/> <xs:attribute name="id" <co - xml:id="progamlisting_book_v5_para_id"/> type="xs:ID" use="optional"/> + xml:id="progamlisting_book_v5_para_id"/> type="xs:ID" use="optional"/> </xs:complexType> </xs:element> @@ -1790,43 +1793,42 @@ public class Memo { </xs:schema></programlisting> - <calloutlist> - <callout arearefs="progamlisting_book_v5_chapter_id"> - <para>Defining an attribute <tag - class="attribute">id</tag> of type <code>ID</code> for - the elements <tag class="element">chapter</tag>, <tag - class="element">para</tag> and <tag - class="element">itemizedList</tag>. This enables an - author to define internal reference targets.</para> - </callout> - - <callout arearefs="progamlisting_book_v5_mixed_link"> - <para>A link is part of the element <tag - class="element">para</tag>'s mixed content model. Thus - an author may define internal references along with - ordinary text.</para> - </callout> - - <callout arearefs="progamlisting_book_v5_link"> - <para>Like in HTML a link may contain text. If converted - to HTML the formatting expectation is a hypertext - link.</para> - </callout> - - <callout arearefs="progamlisting_book_v5_link_linkend"> - <para>The attribute <tag class="attribute">linkend</tag> - holds the reference to an internal target being either a - <tag class="element">chapter</tag>, a <tag - class="element">para</tag> or an <tag - class="element">itemizedList</tag>.</para> - </callout> - </calloutlist> - </answer> - </qandaentry> - </qandadiv> - </qandaset> - </section> + <calloutlist> + <callout arearefs="progamlisting_book_v5_chapter_id"> + <para>Defining an attribute <tag + class="attribute">id</tag> of type <code>ID</code> for the + elements <tag class="element">chapter</tag>, <tag + class="element">para</tag> and <tag + class="element">itemizedList</tag>. This enables an author + to define internal reference targets.</para> + </callout> + + <callout arearefs="progamlisting_book_v5_mixed_link"> + <para>A link is part of the element <tag + class="element">para</tag>'s mixed content model. Thus an + author may define internal references along with ordinary + text.</para> + </callout> + + <callout arearefs="progamlisting_book_v5_link"> + <para>Like in HTML a link may contain text. If converted + to HTML the formatting expectation is a hypertext + link.</para> + </callout> + + <callout arearefs="progamlisting_book_v5_link_linkend"> + <para>The attribute <tag class="attribute">linkend</tag> + holds the reference to an internal target being either a + <tag class="element">chapter</tag>, a <tag + class="element">para</tag> or an <tag + class="element">itemizedList</tag>.</para> + </callout> + </calloutlist> + </answer> + </qandaentry> + </qandadiv> + </qandaset> </section> </section> - </chapter> - + </section> +</chapter>