A matter of style and referential integrity!

Discussion in 'XML' started by earthling, Mar 15, 2005.

  1. earthling

    earthling Guest

    I've included below a fragment of an XML Schema (XSD). Note the
    'localize' complexType used in three situations (twice in the 'site'
    element, and once in the 'page' element). The specifications require
    that there be unique @language text nodes within each 'localize'.
    I was able to describe the constraint as shown, i.e., including key in
    each localize type element. Is there an elegant way of specifying this
    constraint just once without resorting to this repetitive text?

    To my second question I have not found an answer. The 'site' element
    is a root element, it has the @homepage attribute whose value should
    be the unique @id of a 'page' element (note the homepageFK keyref.)
    The XML validates correctly even if the homepage does not exist!


    <xs:complexType name="localize">
    <xs:sequence maxOccurs="unbounded">
    <xs:element name="text">
    <xs:complexType>
    <xs:simpleContent>
    <xs:extension base="xs:string">
    <xs:attribute name="language" type="xs:language" use="required"
    />
    <xs:attribute name="modified" type="xs:dateTime" />
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>

    <xs:element name="site">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="description" type="localize" minOccurs="0">
    <xs:key name="siteDescriptionPK">
    <xs:selector xpath="./text" />
    <xs:field xpath="@language" />
    </xs:key>
    </xs:element>
    <xs:element name="keywords" type="localize" minOccurs="0" >
    <xs:key name="siteKeywordsPK">
    <xs:selector xpath="./text" />
    <xs:field xpath="@language" />
    </xs:key>
    </xs:element>
    <xs:element ref="page" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
    <xs:attribute name="homepage" type="xs:NCName" use="required" />

    <xs:key name="pagePK">
    <xs:selector xpath=".//page" />
    <xs:field xpath="@id" />
    </xs:key>
    <xs:keyref name="homepageFK" refer="pagePK">
    <xs:selector xpath="." />
    <xs:field xpath="@homepage" />
    </xs:keyref>
    </xs:complexType>

    <xs:element name="page">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="title" type="localize" >
    <xs:key name="pageTitlePK">
    <xs:selector xpath="./text" />
    <xs:field xpath="@language" />
    </xs:key>
    </xs:element>
    </xs:sequence>
    <xs:attribute name="id" type="xs:NCName" use="required" />
    </xs:complexType>
    </xs:element>


    <site homepage="myhomepage">
    <description>
    <text language="en">bla bla bla</text>
    <text language="fr">blu blu blu</text>
    <text language="it">bli bli bli</text>
    </description>
    <page id="home" />
    <page id="photos" />
    <page id="download" />
    </site>
     
    earthling, Mar 15, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul Johnson

    Business Rules & Referential Integrity

    Paul Johnson, Nov 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    565
    Paul Johnson
    Nov 20, 2004
  2. terry

    Mysql referential integrity

    terry, Sep 9, 2003, in forum: Java
    Replies:
    1
    Views:
    507
    SS Tsay
    Sep 9, 2003
  3. Paul Daly
    Replies:
    0
    Views:
    530
    Paul Daly
    Jan 12, 2007
  4. Weasley
    Replies:
    0
    Views:
    402
    Weasley
    Feb 2, 2010
  5. Guest
    Replies:
    2
    Views:
    171
    Guest
    Aug 13, 2004
Loading...

Share This Page