Reputation: 61538
I am looking for a way to have an attribute of type xs:string with a minimum length.
I have found a way to do it here, but the solution involves introducing a new type.
As i am using XML mapping/binding, it results in a shiny new class (cluttering the code with its presence as well as additional method calls) which is totally useless - it is still just a plain old String
.
Is there a way to avoid introducing the custom type?
Upvotes: 1
Views: 516
Reputation: 18061
You shouldn't need to declare a new (named) type - just put the restriction inside your attribute definition:
<xs:element name="foo">
<xs:complexType>
<xs:attribute name="bar">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="5" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
Upvotes: 4