2012-04-05 98 views
6

任何人都可以幫我添加一個限制到這個模式文件(OwnerEnglishName)嗎?我知道如何用簡單的方式來做到這一點,而在複雜的類型中,我不知道如何去做。誰能幫忙?如何將限制添加到XML(XSD)架構中的複雜類型?

非常感謝。

原始XML:

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

架構(無限制):

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

的限制:

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

回答

5

這將做到這一點: -

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

以下是可用於此架構的可接受的XML

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