views:

323

answers:

1

I have an attributeGroup defined in my XSD schema. From what I've read and tried out, there is no way I could specify the optionality of the usage of whole group (so that either all of the attributes are specified, or none), something like:

 <xs:attributeGroup name="NameDesc">
    <xs:attribute name="n" type="xs:string" use="required"/>
    <xs:attribute name="d" type="xs:string" use="required"/>
    <xs:attribute name="uinf" type="xs:string" use="required"/>
  </xs:attributeGroup>

  <xs:complexType name="g">
    <xs:attributeGroup ref="tns:NameDesc" use="optional" />
  </xs:complexType>

(note the use="required" I've added in the attributeGroup reference, which is not allowed). Am I right or is there a way to achieve this?

I've read http://stackoverflow.com/questions/511148/xsd-how-to-depend-the-use-attribute-required-optional-with-the-other-value, but I'm not sure this applies to my case.

+2  A: 

As far as I know (someone please correct me if I'm wrong), it's impossible to make attributes dependent like that.

Could you consider making the attributeGroup an actual element? That way the whole element could be present or not as a child element.

This would also be a better design if you were mapping your schema to objects.

womp
Yes, that would probably be a better option. Thanks, I haven't though of that.
Igor Brejc
Could you simulate it by applying different types to elements of the same name,and only one of the types has the attribute group? i.e. XML polymorphism, like <billTo xsi:type="ipo:USAddress">. I'm not saying it would be practical :-)
13ren