Friday, April 29, 2011

XSD - one of 2 attributes is required?

Hi, Is there a way to specify that one of 2 attributes is required in XSD?

for example, i have a definition like this.

<xs:attribute name="Name" type="xs:string" use="optional" />
<xs:attribute name="Id" type="xs:string" use="optional" />

I want to be able to define that atleast one of these is required. Is that possible?

From stackoverflow
  • No, I don't think you can do that with attributes. You could wrap two <xs:element> into a <xs:choice> - but for attributes, there's no equivalent construct, I'm afraid.

    Marc

    Alnitak : yes, that's my understanding too.
    : Thanks so much for the answer. Sorry for the delay in marking this as the answer. Newbie here..
  • Marc is quite right... You cannot have xs:attribute child elements inside a xs:choice parent element in XSD.

    The logic seems to be that if two instances of an element have a mutually exclusive set of attributes then they are logically two different elements.

    A workaround for this has been presented by Jeni Tennison here.

0 comments:

Post a Comment