1

I stumbled upon a problem when i tried to something like this

<root>
    <ele type="a">
        <atr1>first</atr1>
    </ele>
    <ele type="b">
        <atr2>first</atr2>
    </ele>
</root>

when i was trying to enforce that givven element can only have respective child elements if their attribute is set to respective values, that is inthis case, if it has "a", it can't have child .

But i can't really figure out how to do this in xml 1.0

Zerg Overmind
  • 955
  • 2
  • 14
  • 28
  • 1
    I believe (but can't quote the spec at the moment) that you cannot do this. The best you could do would be to have `` and `` elements. – Jim Garrison Mar 26 '18 at 21:50
  • It should be possible to do somehow. Found stuff like that in some old lectures on xml but there were no solutions to them nor any explanation. – Zerg Overmind Mar 26 '18 at 22:02
  • As @JimGarrison commented and Michael Kay answered, you cannot represent such constraints in XSD 1.0. See duplicate link for how to do it using XSD 1.1's Conditional Type Assignment. – kjhughes Mar 26 '18 at 22:39

1 Answers1

2

You can't do this kind of thing with XSD 1.0, it needs version 1.1: either assertions, or conditional type assignment will do the job.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Is there a way i can allow at least the existance of multiple versions? something like choice with sequence instead of single element? – Zerg Overmind Mar 26 '18 at 23:11
  • You can make everything optional. But there is no way in XSD 1.0 to say "if this element is like this, then some other element must be like that". – Michael Kay Mar 26 '18 at 23:40