Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » XML Schema Definition (XSD) » XSD features restricting base class
XSD features restricting base class [message #68570] Mon, 10 July 2006 07:30 Go to next message
Eclipse User
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--
Re: XSD features restricting base class [message #68580 is a reply to message #68570] Mon, 10 July 2006 08:50 Go to previous message
Eclipse User
Originally posted by: merks.ca.ibm.com

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

Kannan,

You can't write a constraint that disallows only certain subclasses that
would otherwise be valid. In fact, you should note that XML Schema
itself doesn't even allow you to constrain which type of object may be
referenced by an IDREF or an anyURI.


Kannan Ekanath wrote:

> 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
>
> ------------------------------------------------------------ ------------
>
><?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>
>
>


--------------050907060407030706050504
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kannan,<br>
<br>
You can't write a constraint that disallows only certain subclasses
that would otherwise be valid.&nbsp;&nbsp; In fact, you should note that XML
Schema itself doesn't even allow you to constrain which type of object
may be referenced by an IDREF or an anyURI.<br>
<br>
<br>
Kannan Ekanath wrote:
<blockquote cite="mide8tdkg$g80$1@utils.eclipse.org" type="cite">Hi
Group,
<br>
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,
<br>
<br>
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 :)
<br>
<br>
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.
<br>
<br>
Can someone tell me if this can be possible in XSD? I am not able to
get the &lt;xsd:restriction&gt; 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.
<br>
<br>
Thanks,
<br>
Kannan
<br>
<pre wrap="">
<hr size="4" width="90%">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsd:schema xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a> xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>&gt;
&lt;xsd:element name="Library"&gt;
&lt;xsd:complexType&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="library" type="LibraryType" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;/xsd:element&gt;
&lt;xsd:complexType name="LibraryType"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="book" type="Book" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;xsd:element name="writer" type="Writer" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="bookName" type="xsd:string" minOccurs="1" maxOccurs="1"/&gt;
&lt;xsd:element name="authors" ecore:reference="Writer" ecore:opposite="books" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="writerName" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;xsd:element name="books" ecore:reference="Book" ecore:opposite="authors" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FinanceBook"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="financeSubjectName" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FunBook"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="funSubjectName" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FunWriter"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="writerStyle" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="SeriousWriter"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="seriousnessLevel" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;


&lt;/xsd:schema&gt;
</pre>
</blockquote>
<br>
</body>
</html>

--------------050907060407030706050504--
Re: XSD features restricting base class [message #598342 is a reply to message #68570] Mon, 10 July 2006 08:50 Go to previous message
Ed Merks is currently offline Ed Merks
Messages: 26013
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050907060407030706050504
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Kannan,

You can't write a constraint that disallows only certain subclasses that
would otherwise be valid. In fact, you should note that XML Schema
itself doesn't even allow you to constrain which type of object may be
referenced by an IDREF or an anyURI.


Kannan Ekanath wrote:

> 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
>
> ------------------------------------------------------------ ------------
>
><?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>
>
>


--------------050907060407030706050504
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Kannan,<br>
<br>
You can't write a constraint that disallows only certain subclasses
that would otherwise be valid.&nbsp;&nbsp; In fact, you should note that XML
Schema itself doesn't even allow you to constrain which type of object
may be referenced by an IDREF or an anyURI.<br>
<br>
<br>
Kannan Ekanath wrote:
<blockquote cite="mide8tdkg$g80$1@utils.eclipse.org" type="cite">Hi
Group,
<br>
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,
<br>
<br>
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 :)
<br>
<br>
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.
<br>
<br>
Can someone tell me if this can be possible in XSD? I am not able to
get the &lt;xsd:restriction&gt; 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.
<br>
<br>
Thanks,
<br>
Kannan
<br>
<pre wrap="">
<hr size="4" width="90%">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xsd:schema xmlns:ecore=<a class="moz-txt-link-rfc2396E" href="http://www.eclipse.org/emf/2002/Ecore">"http://www.eclipse.org/emf/2002/Ecore"</a> xmlns:xsd=<a class="moz-txt-link-rfc2396E" href="http://www.w3.org/2001/XMLSchema">"http://www.w3.org/2001/XMLSchema"</a>&gt;
&lt;xsd:element name="Library"&gt;
&lt;xsd:complexType&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="library" type="LibraryType" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;/xsd:element&gt;
&lt;xsd:complexType name="LibraryType"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="book" type="Book" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;xsd:element name="writer" type="Writer" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="bookName" type="xsd:string" minOccurs="1" maxOccurs="1"/&gt;
&lt;xsd:element name="authors" ecore:reference="Writer" ecore:opposite="books" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="writerName" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/&gt;
&lt;xsd:element name="books" ecore:reference="Book" ecore:opposite="authors" minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FinanceBook"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="financeSubjectName" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FunBook"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Book"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="funSubjectName" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="FunWriter"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="writerStyle" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;
&lt;xsd:complexType name="SeriousWriter"&gt;
&lt;xsd:complexContent&gt;
&lt;xsd:extension base="Writer"&gt;
&lt;xsd:sequence&gt;
&lt;xsd:element name="seriousnessLevel" type="xsd:string"/&gt;
&lt;/xsd:sequence&gt;
&lt;/xsd:extension&gt;
&lt;/xsd:complexContent&gt;
&lt;/xsd:complexType&gt;


&lt;/xsd:schema&gt;
</pre>
</blockquote>
<br>
</body>
</html>

--------------050907060407030706050504--
Previous Topic:XSD features restricting base class
Next Topic:The xs:element with a ref attribute does not show the link
Goto Forum:
  


Current Time: Thu Aug 28 09:34:52 EDT 2014

Powered by FUDForum. Page generated in 0.02250 seconds