Relax NG : Optional Element(s)

T

Tookelso

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 <defaults> element. There are
5 settings which *must* be defined in the <defaults> section.

The configuration file also has <database> elements. A database can
override any of the 5 settings in the <defaults> section.

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 <defaults> element, but any of the elements
optionally be overridden by the <database> element-->
</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 <database> element, instead
of all 5 overrides, I get a "required element missing" error.

Any ideas?

Thanks
--Took
 
B

Bjoern Hoehrmann

* (e-mail address removed) 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 <defaults> element. There are
5 settings which *must* be defined in the <defaults> section.

The configuration file also has <database> elements. A database can
override any of the 5 settings in the <defaults> section.

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 <defaults> element, but any of the elements
optionally be overridden by the <database> element-->
</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 <database> element, 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top