473,586 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

enforce subelements to be of a specific type in XSD?

Hi all, I'm trying to something that I'm sure must be possible within the
schema language but I cannot seem to work it out.

Briefly, I am defining a multi-tiered base structure - each tier has its own
complextype defined with a base CT having the structure that others should
follow.

At the leaf ends of some areas I want to restrict the type of elements that
are defined in restriction extended types but cannot find the correct way to
do it.

Take the following example. I would like to be able to define many different
specific Animal CTs based from Animal CT (Tiger, wilderbeast, giraffe etc)
and be able to define "per specific animal CT" what other specific animal
CTs can be their friend (it is unlikely a wilderbeast will be friends with a
Tiger for example :) ). Each specific animal CT should be able to specify an
unlimited number of elements based on Animal type, but any other type should
not be allowed.

Firstly is this actually possible to protect content models in such a way
and if so how. I can not get my head around how I can express such a type
restriction.

The following example is one technique I've tried and it is invalid ("The
content model of complex type 'MonkeyFriends' is not a valid restriction of
the contact model of complex type 'AnimalFriends' )

Many thanks for any suggestions.

-=- Brett

<xs:complexTy pe name="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="AnimalFri ends">
<xs:choice>
<xs:element name="AnyAnimal Type" type="Animal"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="Monkey">
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="MonkeyFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="MonkeyFri ends">
<xs:complexCont ent>
<xs:restricti on base="AnimalFri ends">
<xs:choice>
<xs:element name="OnlyMonke yFriends" type="Animal"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:schema>
Jul 20 '05 #1
2 1412
My apologies - the reason I got the error in the example I gave was due to
conflicting derived By settings in the CT vs local elements (why does XMLspy
allow such behaviour?.. )

Anyway - here is a slightly modified xsd that if you remove the
SpecialMonkeyFr iends element in MonkeyFriends, will validate correctly, but
I want to be able to specify as many elements as I want for the
MonkeyFriends but only of the Animal type.

Again, I do understand why it doesn't validate, but how can I express in the
XSD what I really want?

Thanks
-=- Brett

<xs:complexTy pe name="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="AnimalFri ends">
<xs:choice>
<xs:element name="AnyAnimal Type" type="Animal" maxOccurs="unbo unded"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="Monkey">
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="MonkeyFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="MonkeyFri ends">
<xs:complexCont ent>
<xs:restricti on base="AnimalFri ends">
<xs:choice>
<xs:element name="NormalMon keyFriends">
<xs:complexType >
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:element>
<xs:element name="SpecialMo nkeyFriends">
<xs:complexType >
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
"Brett Gerhardi" <br************ @nildram.net> wrote in message
news:Jr******** ************@pi pex.net...
Hi all, I'm trying to something that I'm sure must be possible within the
schema language but I cannot seem to work it out.

Briefly, I am defining a multi-tiered base structure - each tier has its
own complextype defined with a base CT having the structure that others
should follow.

At the leaf ends of some areas I want to restrict the type of elements
that are defined in restriction extended types but cannot find the correct
way to do it.

Take the following example. I would like to be able to define many
different specific Animal CTs based from Animal CT (Tiger, wilderbeast,
giraffe etc) and be able to define "per specific animal CT" what other
specific animal CTs can be their friend (it is unlikely a wilderbeast will
be friends with a Tiger for example :) ). Each specific animal CT should
be able to specify an unlimited number of elements based on Animal type,
but any other type should not be allowed.

Firstly is this actually possible to protect content models in such a way
and if so how. I can not get my head around how I can express such a type
restriction.

The following example is one technique I've tried and it is invalid ("The
content model of complex type 'MonkeyFriends' is not a valid restriction
of the contact model of complex type 'AnimalFriends' )

Many thanks for any suggestions.

-=- Brett

<xs:complexTy pe name="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="AnimalFri ends">
<xs:choice>
<xs:element name="AnyAnimal Type" type="Animal"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="Monkey">
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="MonkeyFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="MonkeyFri ends">
<xs:complexCont ent>
<xs:restricti on base="AnimalFri ends">
<xs:choice>
<xs:element name="OnlyMonke yFriends" type="Animal"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:schema>

Jul 20 '05 #2
I have been trying to research this further.

Perhaps the only way to do this would be to drop the base class into its own
namespaced file then include it and use Any with its target namespace?

Is the only way to do this by using namespaces and the any type?

Regards
-=- Brett

"Brett Gerhardi" <br************ @nildram.net> wrote in message
news:X-*************** *****@pipex.net ...
My apologies - the reason I got the error in the example I gave was due to
conflicting derived By settings in the CT vs local elements (why does
XMLspy allow such behaviour?.. )

Anyway - here is a slightly modified xsd that if you remove the
SpecialMonkeyFr iends element in MonkeyFriends, will validate correctly,
but I want to be able to specify as many elements as I want for the
MonkeyFriends but only of the Animal type.

Again, I do understand why it doesn't validate, but how can I express in
the XSD what I really want?

Thanks
-=- Brett

<xs:complexTy pe name="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="AnimalFri ends">
<xs:choice>
<xs:element name="AnyAnimal Type" type="Animal" maxOccurs="unbo unded"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="Monkey">
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="MonkeyFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="MonkeyFri ends">
<xs:complexCont ent>
<xs:restricti on base="AnimalFri ends">
<xs:choice>
<xs:element name="NormalMon keyFriends">
<xs:complexType >
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:element>
<xs:element name="SpecialMo nkeyFriends">
<xs:complexType >
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
"Brett Gerhardi" <br************ @nildram.net> wrote in message
news:Jr******** ************@pi pex.net...
Hi all, I'm trying to something that I'm sure must be possible within the
schema language but I cannot seem to work it out.

Briefly, I am defining a multi-tiered base structure - each tier has its
own complextype defined with a base CT having the structure that others
should follow.

At the leaf ends of some areas I want to restrict the type of elements
that are defined in restriction extended types but cannot find the
correct way to do it.

Take the following example. I would like to be able to define many
different specific Animal CTs based from Animal CT (Tiger, wilderbeast,
giraffe etc) and be able to define "per specific animal CT" what other
specific animal CTs can be their friend (it is unlikely a wilderbeast
will be friends with a Tiger for example :) ). Each specific animal CT
should be able to specify an unlimited number of elements based on Animal
type, but any other type should not be allowed.

Firstly is this actually possible to protect content models in such a way
and if so how. I can not get my head around how I can express such a type
restriction.

The following example is one technique I've tried and it is invalid ("The
content model of complex type 'MonkeyFriends' is not a valid restriction
of the contact model of complex type 'AnimalFriends' )

Many thanks for any suggestions.

-=- Brett

<xs:complexTy pe name="Animal">
<xs:choice>
<xs:element name="Friends" type="AnimalFri ends"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="AnimalFri ends">
<xs:choice>
<xs:element name="AnyAnimal Type" type="Animal"/>
</xs:choice>
</xs:complexType>
<xs:complexTy pe name="Monkey">
<xs:complexCont ent>
<xs:restricti on base="Animal">
<xs:choice>
<xs:element name="Friends" type="MonkeyFri ends"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
<xs:complexTy pe name="MonkeyFri ends">
<xs:complexCont ent>
<xs:restricti on base="AnimalFri ends">
<xs:choice>
<xs:element name="OnlyMonke yFriends" type="Animal"/>
</xs:choice>
</xs:restriction>
</xs:complexConte nt>
</xs:complexType>
</xs:schema>


Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1530
by: thomas | last post by:
Hello all Im having problems with selecting subelements from a dynamic created RTF converted to a node-set: i have hardcodet this example: the xml structure: <xsl:variable name="test">
1
1083
by: dizzyhaze | last post by:
Here is a sample of the kind of XML I'm working with: <root> <elemt>Something is ro<lig>tt</lig>en in the state of <emph>Den</emph>mark</elemt> </root> I would like to be able to extract the contents of <elemt> as a string without the subelements and with the integrity of the words unaffected...for example:
7
3689
by: gino | last post by:
Dear all, My monitor was set to 1600x1200 so the fonts in IE is too small for me even when I set the "View->Text Size->Largest"... I don't have previlage to change the monitor resolution... so I have to try to "hardcode" IE to display any webpage by a scale of 200%...
2
1306
by: noone | last post by:
A typical inventory management system would have people linked to items that link to other items. However in what I'm trying to do, PCs are one of the inventory items. One PC can be linked to many monitors and harddisks etc, but only 1 motherboard. How do I enforce this? Not every item uses a motherboard, so I didn't put a 'Motherboard'...
23
3166
by: Ken Turkowski | last post by:
The construct (void*)(((long)ptr + 3) & ~3) worked well until now to enforce alignment of the pointer to long boundaries. However, now VC++ warns about it, undoubtedly to help things work on 64 bit machines, i.e. with 64 bit pointers. In the early days of C, where there were problems with the size of int being 16 or 32 bits, the response...
2
1620
by: Mehdi | last post by:
Hi, I need to pass an URL via a hidden value as follow: <input type="hidden" id="Test" runat="Server"> and on Page_Load I assign a value to this hidden input as follow: Test.Value = "http://www.myserver.com?id=123&name=HomerSimpson";
0
936
by: Daniel Jorge | last post by:
Hi there, I'm in need to create a WebControl with subelements, just like ListBox, DropDownlList and stuff. But, of course, it's myh custom Item and not a ListItem control. The final result should be like this one (HTML / Design-time) <myNamespace:myControl id="myControl"> <myNamespace:myItem property1="teste" property2="teste1"...
36
2053
by: dspfun | last post by:
Hi! Is there any way in C that one can guarantee that instructions are executed in the same order as they are written in the program? For example, say I have the following: instruction1; instruction2; instruction3;
0
1026
by: bogdan | last post by:
Hi, I'd like to make sure that users access pages in a specific sequence. For example, if a site consists of 3 pages, I'd like users to access first Page1.aspx, then Page2.aspx, and then Page3.aspx. But they should be able to go back in a 'random access' mode and be able to access Page1 from Page2, Page2 from Page3, and Page1 from Page3....
0
8200
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1448
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.