By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Relax NG : Optional Element(s)

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
* 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 discussion thread is closed

Replies have been disabled for this discussion.