473,462 Members | 1,128 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XSD question: Allowing one required element and many optional elements.

Hi Guys,

Newbie question here. Part of my xml looks like this.

<node>
<description/>
<config/>
<log/>
<transition/>
<node>

The transition element inside the node is compulsory. The other
elements are optional and can occur as many times (minOccurs="0"
maxOccurs="unbounded").

How do I write an xsd that validates this?

I tried using the choice tag with no success

<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
</xs:choice>
<xs:element ref="transition" minOccurs="1"/>

This apparently is not valid xsd. I can't wrap the transition in
another choice or sequence or all.

<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
<xs:element ref="transition" minOccurs="1"/>
</xs:choice>

This seems to be a valid xsd but doesn't actually validate the xml
properly. That is, even if the transition element is missing in the
xml, the xsd says its valid.

Tried using the <all> tag as well

<xs:all>
<xs:element ref="description" minOccurs="0" />
<xs:element ref="log" minOccurs="0" />
<xs:element ref="config" minOccurs="0" />
<xs:element ref="transition" minOccurs="1"/>
</xs:all>

The problem with this is that I can only define the non transition
elements only once. I cannot put the maxOccurs="unbounded" because it
invalidates the xsd.

I tried all the various combinations of all the above (putting
maxoccurs in the all tag etc etc.)... No go!

It seems to me that there should be an easy solution to this, some
combination that works.
Any help would be much appreciated
Jul 20 '05 #1
8 2324


MENTAT wrote:

Newbie question here. Part of my xml looks like this.

<node>
<description/>
<config/>
<log/>
<transition/>
<node>

The transition element inside the node is compulsory. The other
elements are optional and can occur as many times (minOccurs="0"
maxOccurs="unbounded").

How do I write an xsd that validates this?


How about xs:sequence e.g.

<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element name="description" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="config" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="log" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="transition" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

that way you have the constraints modelled as described. Of course the
order of elements is constrained that way too but your description
doesn't make it clear whether you do not want that.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
Yeah, this seems to work, but I don't want to constrain the order of the elements.
How about xs:sequence e.g.

<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element name="description" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="config" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="log" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="transition" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

that way you have the constraints modelled as described. Of course the
order of elements is constrained that way too but your description
doesn't make it clear whether you do not want that.

Jul 20 '05 #3
A more challenging aspect of the problem:

Lets modify the xml slightly

<root>
<dialog>
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
<transition/>
<dialog>
<transition/>
<\root>

I need a rule that says that its ok if a node doesn't have a transition
as long as the dialog or root has a transition (it is possible for all
3 to have a transition, which is ok). Note that a root can contain many
dialogs and a dialog can contain many nodes.

What i need is some sort of fall through/ sibling navigation, parent
navigation sort of command. How do I go about doing this in XSD?

Jul 20 '05 #4
The following snippet lets you have description,config, and log in any order
any number of times. The only restriction it presents is that transition
element has to be at the end.

<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
</xs:choice>
<xs:element ref="transition" minOccurs="1"/>
</xs:sequence>
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
"MENTAT" <ch********@hotmail.com> wrote in message
news:5a**************************@posting.google.c om...
Yeah, this seems to work, but I don't want to constrain the order of the
elements.
How about xs:sequence e.g.

<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element name="description" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="config" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="log" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="transition" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

that way you have the constraints modelled as described. Of course the
order of elements is constrained that way too but your description
doesn't make it clear whether you do not want that.

Jul 20 '05 #5
Thanks Stan.
I realised that I wouldn't be able to get it working the way I wanted
and would have to make compromises and put in restrictions. In the end
I changed the specs around so that I could use
<xs:all>
<xs:element ref="description" minOccurs="0"/>
<xs:element ref="config" minOccurs="0"/>
<xs:element ref="log" minOccurs="0"/>
<xs:element ref="transition" minOccurs="1"/>
<xs:all>

This way elements can occur in any order and transition is compulsory,
but it means that each element can occur only once. This is something
I just have to live with now.

Thanks once again Stan. How about my question in the other branch of
this thread, regarding the "fall-through" of transitions. Thats the
one driving me up the wall at the moment. Any hints/helps would be
helpful.


"Stan Kitsis [MSFT]" <sk***@microsoft.com> wrote in message news:<42********@news.microsoft.com>...
The following snippet lets you have description,config, and log in any order
any number of times. The only restriction it presents is that transition
element has to be at the end.

<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="description"/>
<xs:element ref="config" />
<xs:element ref="log" />
</xs:choice>
<xs:element ref="transition" minOccurs="1"/>
</xs:sequence>
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
"MENTAT" <ch********@hotmail.com> wrote in message
news:5a**************************@posting.google.c om...
Yeah, this seems to work, but I don't want to constrain the order of the
elements.
How about xs:sequence e.g.

<xs:element name="node">
<xs:complexType>
<xs:sequence>
<xs:element name="description" minOccurs="0"
maxOccurs="unbounded" />
<xs:element name="config" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="log" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="transition" minOccurs="1"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>

that way you have the constraints modelled as described. Of course the
order of elements is constrained that way too but your description
doesn't make it clear whether you do not want that.

Jul 20 '05 #6
I take it from the silence of the newsgroup (and my own frustrated
attempts at finding a solution), that the problem below doesn't
actually have a solution?

Any confirmation would be appreciated as well and would help me get
"closure" on this issue. :-)
ch********@hotmail.com wrote in message news:<11*********************@z14g2000cwz.googlegr oups.com>...
A more challenging aspect of the problem:

Lets modify the xml slightly

<root>
<dialog>
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
<transition/>
<dialog>
<transition/>
<\root>

I need a rule that says that its ok if a node doesn't have a transition
as long as the dialog or root has a transition (it is possible for all
3 to have a transition, which is ok). Note that a root can contain many
dialogs and a dialog can contain many nodes.

What i need is some sort of fall through/ sibling navigation, parent
navigation sort of command. How do I go about doing this in XSD?

Jul 20 '05 #7
You can't do conditions like this in XML Schema. You can try using a big
choice with all possible states

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
<ch********@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
A more challenging aspect of the problem:

Lets modify the xml slightly

<root>
<dialog>
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
<transition/>
<dialog>
<transition/>
<\root>

I need a rule that says that its ok if a node doesn't have a transition
as long as the dialog or root has a transition (it is possible for all
3 to have a transition, which is ok). Note that a root can contain many
dialogs and a dialog can contain many nodes.

What i need is some sort of fall through/ sibling navigation, parent
navigation sort of command. How do I go about doing this in XSD?

Jul 20 '05 #8
I tried doing a choice between all the possible combinations. Doesn't
work. Because at some stage I have to make a choice between the
element node(or dialog) with one data type and the element node (or
dialog) with another data type and XSD doesn't allow that.

Basically somewhere I would have to go

<choice>
<element name="dialog" type="optional_transition"/>
<element name="dialog" type="compulsory_transition"/>
</choice>

This doesn't work because the element name is the same. It can only
choose different elements, not different element types. Same goes for
<all> and all the other tags. There seems to be a choice for elements
themselves but not the element types.

Hmmmm....Bit of a non trivial restriction isn't it. Anyway, at least
now I know its not something i am overlooking.

Thanks again Stan.

"Stan Kitsis [MSFT]" <sk***@microsoft.com> wrote in message news:<42********@news.microsoft.com>...
You can't do conditions like this in XML Schema. You can try using a big
choice with all possible states

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
<ch********@hotmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
A more challenging aspect of the problem:

Lets modify the xml slightly

<root>
<dialog>
<node>
<description/>
<config/>
<log/>
<transition/>
<node>
<transition/>
<dialog>
<transition/>
<\root>

I need a rule that says that its ok if a node doesn't have a transition
as long as the dialog or root has a transition (it is possible for all
3 to have a transition, which is ok). Note that a root can contain many
dialogs and a dialog can contain many nodes.

What i need is some sort of fall through/ sibling navigation, parent
navigation sort of command. How do I go about doing this in XSD?

Jul 20 '05 #9

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

Similar topics

1
by: Gooseman | last post by:
Hi Just getting into XSD and have some questions: If I have several different elements that all have identical attibutes, what is the best way of conveying that in the XSD? Is there a way...
9
by: Weekend | last post by:
Currently, i want to develope a multiple choice exam website. The content of the test is store in an XML file. I want to carry out some function. Could you tell me which programming language should...
2
by: Stewart Johnson | last post by:
Hey All - I'm stuck while trying to write a schema, hoping someone can provide me with a flash of inspiration. One of the elements I'm writing has two attributes, both of which are optional....
4
by: Russell Silva | last post by:
I have a class A with a member variable type vector<foo> which is initialized upon construction (no standard () constructor): class A { protected: vector<foo> foo_vector; public: A(const...
5
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are...
3
by: Amol | last post by:
Hi all, I have a case where I have a element that can appear under multiple elements e.g. <AppFunctions> <UseTemplate name="1"/> <MethodSet name="2"> <UseTemplate name="3" /> <MethodCall...
29
by: Knut Olsen-Solberg | last post by:
I try to change the text in a <p> using getElementById(). I wonder what properties exists, and which one to use here. (The following does not work.) Regards Knut ______________________ ...
3
by: CindyRob | last post by:
I am using .NET framework 1.1 SP1, .NET framework SDK 1.1 SP1, with hotfix 82202, Visual studio .NET 2003 with hotfix 823639. I have generated a proxy class using wsdl.exe from a schema that has an...
0
by: RYoung | last post by:
Hi all, Hope no one minds this long message, but I'm puzzled: --------------- The following is a shortened version of schema located at...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.