473,416 Members | 1,544 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Relax NG : Optional Element(s)

Hello,

I would like to have a group of elements which are *required* in one
context, but each one is *optional* in another context.

For example:
I have a configuration file which has a <defaultselement. There are
5 settings which *must* be defined in the <defaultssection.

The configuration file also has <databaseelements. A database can
override any of the 5 settings in the <defaultssection.

I tried to define a type like this:

<def name="defaultsType">
<!-- The 5 default elements go here. All 5 elements *must* be
defined under the <defaultselement, but any of the elements
optionally be overridden by the <databaseelement-->
</def>

Then I tried to refer to the type as being *required* by the <defaults>
element.

<element name="defaults">
<ref name="defaultsType" />
</element

<!--And then each database can have the defaultsType as being
optional:-->
<element name="database">
<optional><ref name="defaultsType"/></optional>
</element>

However, if I only specify 1 override in my <databaseelement, instead
of all 5 overrides, I get a "required element missing" error.

Any ideas?

Thanks
--Took

Aug 9 '06 #1
1 1435
* To******@yahoo.com wrote in comp.text.xml:
>Hello,

I would like to have a group of elements which are *required* in one
context, but each one is *optional* in another context.

For example:
I have a configuration file which has a <defaultselement. There are
5 settings which *must* be defined in the <defaultssection.

The configuration file also has <databaseelements. A database can
override any of the 5 settings in the <defaultssection.

I tried to define a type like this:

<def name="defaultsType">
<!-- The 5 default elements go here. All 5 elements *must* be
defined under the <defaultselement, but any of the elements
optionally be overridden by the <databaseelement-->
</def>

Then I tried to refer to the type as being *required* by the <defaults>
element.

<element name="defaults">
<ref name="defaultsType" />
</element

<!--And then each database can have the defaultsType as being
optional:-->
<element name="database">
<optional><ref name="defaultsType"/></optional>
</element>

However, if I only specify 1 override in my <databaseelement, instead
of all 5 overrides, I get a "required element missing" error.

Any ideas?
I am unsure why you think this might work, you have a group of five
elements, each element is required, and then you say the group is
optional. So, if no element is present, that's okay because the group
is optional, or you have all required elements, which is okay because
the whole group is there, and in all other cases it's not okay because
the group is not complete. You cannot use a group in the optional case,
you have, if all five subelements are optional, specify for each of
the elements that it is optional. So you go

<element name="database">
<optional>...1...</optional>
<optional>...2...</optional>
<optional>...3...</optional>
<optional>...4...</optional>
<optional>...5...</optional>
</element>

and

<element name="defaults">
<ref name="defaultsType" />
</element

for example.
--
Björn Höhrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Aug 9 '06 #2

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

Similar topics

0
by: Jari Kujansuu | last post by:
I am trying to learn to use jing through JARV interface and I have read JARV User's Guide (http://iso-relax.sourceforge.net/JARV/JARV.html). I have downloaded jingjarv-examples.zip from JARV...
1
by: James McComb | last post by:
Please, can someone tell me how I can express this constraint using Relax NG? I want these documents to be valid: <memo> <code>WithMessage</code> <message>WithMessage means there is a...
6
by: Pieter | last post by:
I've read a lot of posts on "why relax ng is so very good" and on "why w3c xml schema should be the only schema language". I'm, however, still not clear on why I should prefer one over the other. ...
0
by: Geert | last post by:
Hello, I'm trying to write a RELAX NG schema that *only* validates the following XML instance (with mixed content): <div id="1">A<a href="X"/></div> The problem is to constrain the text...
5
by: mhuhn.de | last post by:
I am using XML Schema for quite a while but haven't written a single line of Relax NG yet. For what I know, I cannot define static content within an XML Schema. For example, I have the following...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
4
by: withtape | last post by:
Somebody please, please help me. I'm getting started using Relax NG to describe document schemas. After reading the grammar summarized by http://www.relaxng.org/spec-20011203.html (Section 5), I...
1
by: Gerben Abbink | last post by:
In Relax NG, I understand all other group operators (interleave, choice, oneOrMore, zeroOrMore, optional), but what is the purpose of <group>? Can you give an example?
0
by: Frank Cusack | last post by:
Is it possible to require one or more from a list of optional elements? If I have something like: <element name="parent"> <oneOrMore> <interleave> <optional> <element name="child1"> <text/>...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.