XML-Schema: Attribute Value dependent rules?

A

Andrew Lord

XML-Schema: Attribute Value dependent rules?

As far as I can tell XML-Schema does not permit the sepcification of rules
that only apply if an attribute has a certain value. For example, in the
document below, attribute RemoteServer must be present and non-null if
attribute LocalMachine is false, but need not be present if it is true.

<Configuration>
<Registry LocalMachine="false" RemoteServer="\\SERVER1"
RootKey="HKEY_LOCAL_MACHINE" RegistryKey="MyRegKey"/>
</Configuration>

One solution to this is to allow one of two elements, say LocalRegistry and
RemoteRegistry each with their own attribute sets. Thus we could create a
schema to allow either of the following instance documents:

<Configuration>
<LocalRegistry RootKey="HKEY_LOCAL_MACHINE" RegistryKey="MyRegKey"/>
</Configuration>

or

<Configuration>
<RemoteRegistry Server="\\SERVER1" RootKey="HKEY_LOCAL_MACHINE"
RegistryKey="MyRegKey"/>
</Configuration>

However I don't like this approach. Changing the name of the Element suggests
more differences than really exist, it is after all, just a registry.

The other solution is to keep just the one Registry element and make the
RemoteServer attribute optional, but that means that you cannot validate
the "RemoteServer attribute must be specified if LocalMachine is false" rule.

Both approaches seem to have drawbacks, either clarity suffers or validation
becomes less exact.

Do other people share this view and if so what solutions have you come up with?

TIA

Andrew Lord
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top