XML-Schema: Attribute Value dependent rules?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andrew Lord

    XML-Schema: Attribute Value dependent rules?

    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.

    <Configuratio n>
    <Registry LocalMachine="f alse" RemoteServer="\ \SERVER1"
    RootKey="HKEY_L OCAL_MACHINE" RegistryKey="My RegKey"/>
    </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:

    <Configuratio n>
    <LocalRegistr y RootKey="HKEY_L OCAL_MACHINE" RegistryKey="My RegKey"/>
    </Configuration>

    or

    <Configuratio n>
    <RemoteRegist ry Server="\\SERVE R1" RootKey="HKEY_L OCAL_MACHINE"
    RegistryKey="My RegKey"/>
    </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 "RemoteServ er 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
Working...