views:

351

answers:

2

Hi guys I have a simple XML file with this structure

 ... ...
 <Fields>
  <Field name="MainJob.Id" value="t066_id">
    <Description nullable="false" type="System.Int32" />
  </Field>

What I have actually is this XSD file description:

              <xs:element minOccurs="0" maxOccurs="unbounded" name="Fields">
            <xs:complexType>
              <xs:sequence>
                <xs:element minOccurs="0" maxOccurs="unbounded" name="Field">
                  <xs:complexType>
                    <xs:sequence>
                      <xs:element minOccurs="0" maxOccurs="unbounded" name="Description">
                        <xs:complexType>
                          <xs:attribute name="nullable" type="xs:string" use="required" />                              <xs:attribute name="type" type="xs:string" use="required" />
                          <xs:attribute name="minLength" type="xs:string" use="optional" />
                          <xs:attribute name="maxLength" type="xs:string" use="optional" />
                        </xs:complexType>
                      </xs:element>
                    </xs:sequence>
                    <xs:attribute name="name" type="xs:string" />
                    <xs:attribute name="value" type="xs:string" />
                  </xs:complexType>
                </xs:element>
              </xs:sequence>
            </xs:complexType>
          </xs:element>

How I can define two only available values for the attribute nullable, like 'true' and 'false'? If I nest a SimpleType inside the attribute the .XSD file is not valid anymore. thank you

+1  A: 

Type should be not xs:string but xs:boolean for your example, or you can use enumeration (example).

zzandy
Thank you zzandy.If I use boolean or another data type it's fine but where I have to define a simple type that show my enumeration? Before defining my entire .XSD?
In order to use enumeration you should define a simple type for it anywhere in your schema. The example link above shows how to do it in code and Visual Studio allows to add enumeration type from schema designer.
zzandy
A: 

You can add a simpleType like so:

 <xs:simpleType name="TrueOrFalse">
    <xs:restriction base="xs:string">
      <xs:enumeration value="false"/>
      <xs:enumeration value="true"/>
    </xs:restriction>
  </xs:simpleType>

and then change your nullable to:

<xs:attribute name="nullable" type="TrueOrFalse" use="required" />

Marc

marc_s