Xsd attribute and element validation

I am trying to create an XSD schema that will validate the following xml.

<Item ItemGUID="3F2504E0-4F89-11D3-9A0C-0305E82C3301">The name of the item</Item>

      

I want to check the maximum length of the "ItemGUID" attribute to 36 characters and the "Item name" to 25 characters.

How can this be tested to satisfy the above condition using the xsd schema?

0


a source to share


1 answer


With XML Schema, you can do something like this:

<xs:element name="Item">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="string25">
        <xs:attribute name="ItemGUID" type="string36" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element> 

<xs:simpleType name="string25">
  <xs:restriction base="xs:string">
    <xs:minLength value="1"/>
    <xs:maxLength value="25"/>
  </xs:restriction>
</xs:simpleType>


<xs:simpleType name="string36">
  <xs:restriction base="xs:string">
    <xs:minLength value="1"/>
    <xs:maxLength value="36"/>
  </xs:restriction>
</xs:simpleType>

      



I haven't tried it, but if that doesn't work, it should be very close to what you want.

+4


a source







All Articles