Reputation: 43857
Hopefully this is an easy question. How can I define an XML type such that the type doesn't have a body.
As an example I can define the Foo type as follows...
<xs:complexType name="Foo">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
But that would allow the following...
<Foo id="7">STUFF I DON'T WANT</Foo>
Is there a way I can change the xsd so that the Foo element isn't allowed any body?
Upvotes: 2
Views: 475
Reputation: 9519
Like this:
<xsd:element name="foo">
<xsd:complexType>
<xsd:complexContent>
<xsd:restriction base="xsd:anyType">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xsd:restriction>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
Upvotes: 0
Reputation: 11817
I believe this is what you wanted:
<xs:complexType name="Foo">
<xs:attribute name="id" type="xs:integer" use="required"/>
</xs:complexType>
Upvotes: 3