2012-04-05 9 views
6

Qualcuno può aiutarmi ad aggiungere una restrizione a questo file di schema (per OwnerEnglishName)? So come farlo con un carattere semplice, mentre in un tipo complesso non so come farlo. Qualcuno può aiutare?Come posso aggiungere una restrizione a un tipo complesso nello schema XML (XSD)?

Grazie mille.

XML originale:

<PACIDemoSignedDoc PaciSDocID="HouseOwnerSignedEndorsement"> 
    <OwnerEnglishName OENID="Name"></OwnerEnglishName> 
</PACIDemoSignedDoc> 

Schema (senza limitazioni):

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="PACIDemoSignedDoc" type="PACIDemoSignedDocType" /> 
    <xs:complexType name="PACIDemoSignedDocType"> 
    <xs:sequence> 
     <xs:element name="OwnerEnglishName" type="OwnerEnglishNameType" /> 
    </xs:sequence> 
    <xs:attribute name="PaciSDocID" type="xs:string" /> 
    </xs:complexType> 
    <xs:complexType name="OwnerEnglishNameType"> 
    <xs:attribute name="OENID" type="xs:string" /> 
    </xs:complexType> 
</xs:schema> 

Il Codice di restrizione:

<xs:restriction base="xs:string"> 
    <xs:minLength value="5"/> 
    <xs:maxLength value="100"/> 
</xs:restriction> 

risposta

5

Questo lo farà: -

<?xml version="1.0" encoding="utf-8"?> 
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="PACIDemoSignedDoc" type="PACIDemoSignedDocType" /> 
    <xs:complexType name="PACIDemoSignedDocType"> 
     <xs:sequence> 
      <xs:element name="OwnerEnglishName" type="OwnerEnglishNameType" /> 
     </xs:sequence> 
     <xs:attribute name="PaciSDocID" type="xs:string" /> 
    </xs:complexType> 
    <xs:complexType name="OwnerEnglishNameType"> 
     <xs:simpleContent> 
      <xs:restriction base="NameType"> 
       <xs:minLength value="5"/> 
       <xs:maxLength value="10"/> 
      </xs:restriction> 
     </xs:simpleContent> 
    </xs:complexType> 
    <xs:complexType name="NameType"> 
     <xs:simpleContent> 
      <xs:extension base="xs:string"> 
       <xs:attribute name="OENID" type="xs:string" /> 
      </xs:extension> 
     </xs:simpleContent> 
    </xs:complexType> 
</xs:schema> 

Ecco un esempio XML accettabile con questo schema

<?xml version="1.0" encoding="UTF-8"?> 
<PACIDemoSignedDoc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" PaciSDocID="gggg"> 
    <OwnerEnglishName OENID="9999">GGGGG</OwnerEnglishName> 
</PACIDemoSignedDoc> 
Problemi correlati