Reputation: 26874
In XML Schema, how do I define a ComplexType
that renders like the following?
<ValidationError code="X501">I love cats!</ValidationError>
If I try the following my tools* will say it is not valid
<xsd:complexType name="ValidationErrorType">
<xsd:attribute name="code" type="xsd:string"></xsd:attribute>
<xsd:simpleContent>
<xsd:extension base="xs:string"/>
</xsd:simpleContent>
</xsd:complexType>
Tools I use are Altova XMLSpy for visual editing and wsdl2java to generate classes
Update: I have tried another flavour
<xsd:complexType name="ValidationErrorType">
<xsd:simpleContent>
<xsd:extension base="xs:string">
<xsd:attribute name="code" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Altova said Invalid XML schema: 'Value 'xs:string' is not allowed for attribute 'base'.'
Upvotes: 3
Views: 819
Reputation: 26874
Okay, I learned the lesson
simpleContent
but must appear within the extension
xsd
prefix in my second example which was almost correctThe correct form is
<xsd:complexType name="ValidationErrorType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="code" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
Upvotes: 4