If you need attributes, you have to use a complexType
. But if you also need simple content, then you can define your complexType
as containing simpleContent
and extend it with attributes using a base simple type
In your case, you could do something like this:
<xs:complexType name="itemType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="quantity" type="xs:integer"/>
<xs:attribute name="unit" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
This will allow:
<item quantity="1" unit="slice">bread</item>
You still need to allow more than one <item>
element inside ingredientsType
. If you can have unlimited items, you can use:
<xs:complexType name="ingredientsType">
<xs:sequence>
<xs:element name="item" type="itemType" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>