XSD: Adding attributes to strongly-typed "simple" elements XSD: Adding attributes to strongly-typed "simple" elements xml xml

XSD: Adding attributes to strongly-typed "simple" elements


It's not entirely clear which aspect of the manual solution you regard as horrible; if it's the idea of having to define n different types just because they will need to extend n different base types, then you're stuck.

If it's the idea of having to have n different declarations for the format and isVisible attributes, then you might find it less horrible to use a named attribute group to hold those definitions:

<xs:attributeGroup name="globals">  <xs:attribute name="format" type="xs:string"/>  <xs:attribute name="isVisible" type="xs:boolean"/></xs:attributeGroup>

The declarations of the various complex types you need remain repetitive but are now slightly less verbose:

<xs:complexType name="string">  <xs:simpleContent>    <xs:extension base="xs:string">      <xs:attributeGroup ref="my:globals"/>    </xs:extension>  </xs:simpleContent></xs:complexType><xs:complexType name="dateTime">  <xs:simpleContent>    <xs:extension base="xs:dateTime">      <xs:attributeGroup ref="my:globals"/>    </xs:extension>  </xs:simpleContent></xs:complexType><xs:complexType name="int">  <xs:simpleContent>    <xs:extension base="xs:int">      <xs:attributeGroup ref="my:globals"/>    </xs:extension>  </xs:simpleContent></xs:complexType>

And the declarations of your elements are now slightly simpler than in your 'ideal' case:

<xs:element name="DocumentDescription" type="my:string" /><xs:element name="DocumentDateTime" type="my:dateTime" /><xs:element name="DocumentSize" type="my:int" />


[quote]could do it manually, and horribly, by adding all such attributes to the XSD when I generate it, something like this:[/quote]

I'm afraid this is your only "proper", XSD-schema compatible way to do it.

XSD can be convoluted to author at times - but it helps keeping things safe :-)

Marc


The purpose of an XSD is to describe your data. The purpose of an XSD's type attribute is to describe or define an element. What you want to do is to change the element's definition. If you're changing the description change the type. What you're trying to do is like putting wheels on a thought. "But I want wheels on my thought!" "Sorry, no can do."