Domanda

Sto cercando di creare uno schema XSD che convaliderà il seguente XML.

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

Voglio convalidare la lunghezza massima dell'attributo " ItemGUID " a 36 caratteri e " Il nome dell'articolo " fino a un massimo di 25 caratteri.

Come può essere convalidato per soddisfare la condizione sopra usando lo schema xsd?

È stato utile?

Soluzione

Con XML Schema, puoi fare qualcosa del genere:

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

Non l'ho provato, ma se non funziona dovrebbe essere molto vicino a quello che ti serve.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top