tags:

views:

25

answers:

2

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?

+2  A: 

I believe this is what you wanted:

<xs:complexType name="Foo">
    <xs:attribute name="id" type="xs:integer" use="required"/>
</xs:complexType>
ryanprayogo
That worked great. Thanks!
Pace
A: 

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>
nont