Referencing constraints

Figure 750. Referencing contacts Slide presentation Create comment in forum
<contact id="10" >
    <firstName>Eve </firstName> ... </contact>
<contact id="11" > ◀─────────────────────────┐   
    <firstName>Joe</firstName>... </contact> 
<contact id="12" > ◀─────────────────────────┼─┐ 
    <firstName>Sue</firstName>... </contact> │ │
<appointment date="2031-10-26T18:30:00">     │ │
    <description>Merry X-mas!</description>  │ │
    <participant>11</participant> ───────────┘ │ 
    <participant>12</participant> ─────────────┘ 
</appointment>

Defining unique contact id value 11.

Defining unique contact id value 12.

Referencing <contact> having id value 11.

Referencing <contact> having id value 12.


Figure 751. Violating referential integrity Slide presentation Create comment in forum
<contact id="10" >
    <firstName>Eve </firstName> ... </contact>
<contact id="11" >
    <firstName>Joe</firstName>... </contact>
<contact id="12" > ◀──────────────────────────┐ 
    <firstName>Sue</firstName>... </contact>  
<appointment date="2031-10-26T18:30:00">      
    <description>Merry X-mas!</description>   
    <participant>12</participant> ────────────┘ 
   <participant>123</participant>  ─────▶ ??
</appointment>

Defining unique contact id value 12.

Referencing <contact> having id value 12.

Error: No such <contact id="123">.


Figure 752. Enforcing referential integrity Slide presentation Create comment in forum
<xs:element name="organizer">
  <xs:complexType><xs:sequence> ...
     <xs:element ... maxOccurs="unbounded" ref="appointment"/>
...<xs:key name="primaryKey"> ◀─ reference          
   <xs:selector xpath="contact"/>                       
     <xs:field xpath="@id"/>                          
   </xs:key>                                          
   <xs:keyref name="participants" refer="primaryKey">  
     <xs:selector xpath="appointment/participant"/>    
     <xs:field xpath="."/>                            
    </xs:keyref>                          └────┐       
</xs:element>                                         
<xs:element name="appointment"> ◀──────────────┼───────┘
  <xs:complexType><xs:sequence>                
 ...  <xs:element type="xs:integer" name="participant"  

Multiple appointments inside <organizer>.

Selecting the set of all <appointment>/<participant> elements below current element <organizer>.

Note: The dot in <xs:field xpath="."> is an XPath denoting a current <participant> element's content e.g. the value 3 in <participant>3</participant>.


Figure 753. Participant reference duplicates Slide presentation Create comment in forum
  <appointment date="2031-10-26T18:30:00">
    <description>Merry X-mas!</description>
    <participant>11</participant> ◀─
    <participant>12</participant>   
    <participant>11</participant> ◀─┘
  </appointment>

Figure 754. Solution:New key constraint Slide presentation Create comment in forum
<xs:element name="appointment">
  <xs:complexType>
    <xs:sequence>
          ...
      <xs:element name="participant" type="xs:integer"
          maxOccurs="unbounded"/>
      </xs:sequence>
      ...
  </xs:complexType>

  <xs:key name="uniqueParticipants">
    <xs:selector xpath="participant"/>
    <xs:field xpath="."/>
  </xs:key>
</xs:element>

Figure 755. Participant reference duplicates Slide presentation Create comment in forum
<appointment ...>
    <description>Merry X-mas!</description>
    <participant>11</participant> ◀─
    <participant>12</participant>   
                                     <!-- Duplicate key value [11]
                                          declared for identity
                                          constraint "uniqueParticipants"
                                          of element "appointment". -->
    <participant>11</participant> ◀─┘
  </appointment>

exercise No. 5

Representing extended <memo> instances Create comment in forum

Q:

This exercise is about representing an online messaging system's data store:

<memo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="memo.xsd"
  date="2014-09-24"  priority="medium" >
  <contacts> 
    <entry id="10"> 
      <commonName>Susan Sonntag</commonName>
      <tel>+44332232323</tel> 
      <email>susan23@evermail.com</email> 
      <email>susa112@private.uk</email>
    </entry>
    <entry id="20">
      <commonName>John Balber</commonName>
      <email>balber@hatebook.com</email>
      <tel>017297123232</tel>
      <email>home@balber.org</email>
    </entry>
    <entry id="25">
      <commonName>Mary Palmer</commonName>
      <tel>017297123232</tel>
    </entry>
  </contacts>

  <from contact="10"/> 
  <to contact="20"/> 
  <to contact="25"/>
  <subject>Best whishes</subject>
  <content>
    <para>Have a nice trip!</para>
    <para>I feel <emphasis>very</emphasis>  happy for you. Don't miss <link href="https://www.wikipedia.org">  sharing your results</link>.</para> (11)
  </content>
</memo>

Mandatory @date attribute of appropriate type.

Optional @priority attribute allowing exactly one of {low, medium, high}.

<contacts> defining a list of contacts having at least one <entry>.

Each <entry> represents an individual contact having a unique @id value. Rules:

  • An <entry> must have at least one <email> or <tel> child.

  • <email> and <tel> children may appear in arbitrary order. Hint: Watch out for the <xs:choice> definition.

A telephone number is subject to the following restrictions:

  • A telephone number must start either with 0 or +.

  • Apart from a + sign at the very beginning only digits are allowed.

  • If starting with an (international) + indicator the next character must not be zero. A + indicator must be followed by at least three digits (two representing the country code plus at least one national digit).

Consider Figure 712, “User defined email type ”.

The <from> element represents the memo's sender with @contact referring to an <entry> element. A <memo> has got exactly one sender.

Likewise each <to> element represents a recipient. All recipients form a set (having no duplicates). Thus within a given <memo> all @contact attribute values appearing in <to> elements must be unique.

para elements allow for mixed content possibly containing both <emphasis> and <link> children. An <emphasis> element's formatting expectation is e.g. using bold font weight.

<link> elements are the equivalent to the HTML <a href="..."> element. Hint: XSD offers a type suitable for URI strings.

(11)

There must be at least one <para> child within <content>.

A:

See XSD file.