7

谁能帮我为这个模式文件添加一个限制(对于 OwnerEnglishName)?我知道如何用 simpletype 来做,而在 complextype 中我不知道怎么做。任何人都可以帮忙吗?

非常感谢。

原始 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>
4

1 回答 1

7

这将做到这一点: -

<?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>
于 2012-04-05T10:24:30.620 回答