3

To a simple element with type="xs:int" I would like to add both a restriction and a number of attributes. However, the only way I have seen it done is in a two-step approach:

  1. Declare a named (global) type and put all the restrictions in the named type

  2. Refer to the named type in the base of an <xs:extension> and add the attributes to the extension node.

It could be nice if I could avoid declaring a global named type as the schema is generated dynamically and it would be a lot cleaner to specify all restrictions locally. E.g. like this:

<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:int">
      <xs:minInclusive>2</xs:minInclusive>
      <xs:attribute name="myAttribute" type="xs:boolean" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

or in case of a string-type:

<xs:complexType>
  <xs:simpleContent>
    <xs:extension base="xs:string">
      <xs:enumeration Value="FOO" />
      <xs:enumeration Value="BAR" />
      <xs:enumeration Value="BAZ" />
      <xs:attribute name="myAttribute" type="xs:boolean" />
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

Unfortunately, it does not seem that a "combined" declaration like this is allowed.

someName
  • 1,275
  • 2
  • 14
  • 33

2 Answers2

2

It's not possible, please review: Having both an attribute and a restriction on an element in xml schema answer thou.

Community
  • 1
  • 1
Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • I saw the post but didn't thought it matched my problem. Giving it a closer look, I can see that it actually does. Thanks! – someName Apr 04 '11 at 10:49
1

Unfortunately it's not possible to do it. The way you do it currently (with separate type) is the way to go. Such requests were raised before (though maybe not in SO).

oiavorskyi
  • 2,893
  • 1
  • 20
  • 23