Question

I want to be able to change the expected child elements of a parent element when the parent element has a particular attribute value set.

So the following would validate:

<Parent childConfig="A">
    <Child validForConfigA="ABC"/>
</Parent>

or:

<Parent childConfig="B">
    <Child validForConfigB="XYZ"/>
</Parent>

But this snippet would not validate (because the attribute "validForConfigB" is not valid when the parent's childConfig="A"):

<Parent childConfig="A">
    <Child validForConfigB="ABC"/>
</Parent>

Can this kind of logic work in DTD or XSD?

Était-ce utile?

La solution

Not with a DTD, but with an XML Schema 1.1 validator you should be able to use type alternatives.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top