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

XML-Schema: Attribute Value dependent rules?

P: n/a
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
Jul 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.