Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » XML Schema Definition (XSD) » XSD features restricting base class
XSD features restricting base class [message #598332] Mon, 10 July 2006 11:30
Eclipse UserFriend
Originally posted by: kannan.ekanath.gmail.com

This is a multi-part message in MIME format.
--------------090105070109080301040308
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Group,
I have an xsd where i want to extend an element type but also control
the parent types data. Let us take a simple library example,

We have types Book and Writer (A book has many "authors" and a writer
has "books"). Now there are subclasses for Book like FunBook, TechBook
and Author has subclasses like FreelanceWriter, SeriousWriter etc. (OO
purists please excuse the usage of inheritance paradigm here :)

Now, i want to impose some restrictions on SeriousWriter. For example,
although he can write many types of books, i want to enforce that "He
cannot write FunBooks". Similarly a Techbook not being able to authored
by a "FunWriter" etc.

Can someone tell me if this can be possible in XSD? I am not able to get
the <xsd:restriction> element to work here. The constraint here being
that i want the "authors" and "books" relation *only* in the base class?
I have also attached the sample xsd.

Thanks,
Kannan

--------------090105070109080301040308
Content-Type: text/xml;
name="book.xsd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="book.xsd"

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="Library">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="library" type="LibraryType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="LibraryType">
<xsd:sequence>
<xsd:element name="book" type="Book" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="writer" type="Writer" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Book">
<xsd:sequence>
<xsd:element name="bookName" type="xsd:string" minOccurs="1" maxOccurs="1"/>
<xsd:element name="authors" ecore:reference="Writer" ecore:opposite="books" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Writer">
<xsd:sequence>
<xsd:element name="writerName" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element name="books" ecore:reference="Book" ecore:opposite="authors" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="FinanceBook">
<xsd:complexContent>
<xsd:extension base="Book">
<xsd:sequence>
<xsd:element name="financeSubjectName" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="FunBook">
<xsd:complexContent>
<xsd:extension base="Book">
<xsd:sequence>
<xsd:element name="funSubjectName" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="FunWriter">
<xsd:complexContent>
<xsd:extension base="Writer">
<xsd:sequence>
<xsd:element name="writerStyle" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="SeriousWriter">
<xsd:complexContent>
<xsd:extension base="Writer">
<xsd:sequence>
<xsd:element name="seriousnessLevel" type="xsd:string"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>


</xsd:schema>

--------------090105070109080301040308--
Previous Topic:DocumentRoot
Next Topic:XSD features restricting base class
Goto Forum:
  


Current Time: Fri Apr 26 04:29:43 GMT 2024

Powered by FUDForum. Page generated in 0.04804 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top