3
votes

I've got to build an XSD file for XML structure verifying purposes, as usual.

After generating the XSD (with XMLSpy), I've found one portion of the file that is giving me trouble. I've got an enumeration like this:

    <xs:enumeration value="1"/>
    <xs:enumeration value="1011"/>
    <xs:enumeration value="1032"/>

and so on. The problem is, any given integer in this enum must be considered valid, and I cannot write enumeration tags from 1 to, let's say, 65635.

And I also don't know how much of this enum elements will be necessary, because the number of these enumeration tags on the XML file is not fixed!

How can I tell the XSD that any integer value is ok, and that there is no minimal or maximal matches on the XML file for this enumeration?

Thanks in advance (and sorry for my english!)

2

2 Answers

6
votes

Your question doesn't show enough information to tell a precisely correct answer, but this will probably solve your problem. 

You probably have some code like this:

<xs:element name="foobar" type="enumType"/>

<xs:simpleType name="enumType">
  <xs:restriction base="xs:integer">
    <xs:enumeration value="1"/>
    <xs:enumeration value="1011"/>
    <xs:enumeration value="1032"/>
  </xs:restriction>
</xs:simpleType>

This piece of schema defines an element <foobar> and a simple type enumType that is the content type of the <foobar> element. So, you asked:

How can I tell the XSD that any integer value is ok, and that there is no minimal or maximal matches on the XML file for this enumeration?

You don't need to enumerate separately all the valid values for <foobar> like you have to do with DTD. Instead you can just use the predefined types of XML Schema in the type attribute.

Here is an example code that defines an element <foobar> and allows it to contain any integer.

<xs:element name="foobar" type="xs:integer"/>

If I misinterpreted your question, please leave a comment and define your problem more closely. Also revealing more of your schema would be helpful.

4
votes

Why do you have to use a enumeration and not a simple integer type?