在XML

时间:2015-06-17 03:19:49

标签: xml xsd

这里有我的XML Schema。我正在尝试确定Family_Client是否允许多个客户端,因为Family表可能有多个家庭成员。

<xsd:element name="Nzfsg_Families" >
  <xsd:complexType>
    <xsd:sequence>               
        <xsd:element name="Family" minOccurs="1" maxOccurs="unbounded">
            <xsd:complexType>
                <xsd:sequence>

                    <xsd:element name="FamilyID" type="xsd:int" minOccurs="1" maxOccurs="1"/>

                    <xsd:element name="PostalAddress" minOccurs="0">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="MailingAddress1" type="xsd:string"   minOccurs="0" />
                          <xsd:element name="MailingAddress2" type="xsd:string"  minOccurs="0"  />
                          <xsd:element name="MailingCity" type="xsd:string"   minOccurs="0" />
                          <xsd:element name="MailingPostCode" type="xsd:string" minOccurs="0"/>                     
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>

                    <xsd:element name="ClientAddress" minOccurs="1" maxOccurs="1">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="HomeAddress1" type="xsd:string"   minOccurs="0" />
                          <xsd:element name="HomeAddress2" type="xsd:string"  minOccurs="0"  />
                          <xsd:element name="HomeCity" type="xsd:string"   minOccurs="0" />
                          <xsd:element name="HomePostcode" type="xsd:string" minOccurs="0"/>                      
                        </xsd:sequence>
                      </xsd:complexType>
                    </xsd:element>

                    <xsd:element name="Family_Client" minOccurs="1" maxOccurs="10">
                      <xsd:complexType>
                        <xsd:sequence>
                          <xsd:element name="ClientID" type="xsd:int" />
                          <xsd:element name="Title" type="Title" minOccurs="0"/>
                          <xsd:element name="FirstName" type="xsd:string"   />
                          <xsd:element name="LastName" type="xsd:string" />
                          <xsd:element name="MiddleName" type="xsd:string" minOccurs="0" />
                          <xsd:element name="PreferredName" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Email" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Gender" type="Gender" minOccurs="0" />
                          <xsd:element name="Dob" type="xsd:date" minOccurs="0" />
                          <xsd:element name="HomePhone" type="xsd:string" minOccurs="0" />
                          <xsd:element name="MobilePhone" type="xsd:string" minOccurs="0" />
                          <xsd:element name="BusinessPhone" type="xsd:string" minOccurs="0" />
                          <xsd:element name="WorkEmail" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Fax" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Smoker" type="YesOrNo" minOccurs="0" />
                          <xsd:element name="BestTimeToCall" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Occupation" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Employer" type="xsd:string" minOccurs="0" />
                          <xsd:element name="Industry" type="xsd:string" minOccurs="0" />
                        </xsd:sequence>

                      </xsd:complexType>
                    </xsd:element>

                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>


    </xsd:sequence>
  </xsd:complexType>
</xsd:element>

<xsd:simpleType name="YesOrNo">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="Yes"/>
    <xsd:enumeration value="No"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="Gender">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="Male"/>
    <xsd:enumeration value="Female"/>
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="Title">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="Mr"/>
    <xsd:enumeration value="Mrs"/>
    <xsd:enumeration value="Ms"/>
    <xsd:enumeration value="Miss"/>
    <xsd:enumeration value="Dr"/>
  </xsd:restriction>
</xsd:simpleType>

此架构是否支持多个Family_Client子元素,还是我还需要做其他事情?

2 个答案:

答案 0 :(得分:3)

在序列中,任何具有maxOccurs&gt;的元素可以重复1。根据您的代码,将允许1到10个<Family_Client />个元素。如果要允许无限数量的家庭客户端,也可以将属性更改为maxOccurs =“unbounded”。

答案 1 :(得分:2)

您的架构确实适用于多个Family和Family_Client元素。例如,这是一个验证XSD的XML文件:

<?xml version="1.0" encoding="UTF-8"?>
<Nzfsg_Families xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/C:/temp/Untitled1.xsd">
    <Family>
        <FamilyID>2147483647</FamilyID>
        <PostalAddress>
            <MailingAddress1>MailingAddress10</MailingAddress1>
            <MailingAddress2>MailingAddress20</MailingAddress2>
            <MailingCity>MailingCity0</MailingCity>
            <MailingPostCode>MailingPostCode0</MailingPostCode>
        </PostalAddress>
        <ClientAddress>
            <HomeAddress1>HomeAddress10</HomeAddress1>
            <HomeAddress2>HomeAddress20</HomeAddress2>
            <HomeCity>HomeCity0</HomeCity>
            <HomePostcode>HomePostcode0</HomePostcode>
        </ClientAddress>
        <Family_Client>
            <ClientID>2147483647</ClientID>
            <Title>Mr</Title>
            <FirstName>FirstName0</FirstName>
            <LastName>LastName0</LastName>
            <MiddleName>MiddleName0</MiddleName>
            <PreferredName>PreferredName0</PreferredName>
            <Email>Email0</Email>
            <Gender>Male</Gender>
            <Dob>2006-05-04</Dob>
            <HomePhone>HomePhone0</HomePhone>
            <MobilePhone>MobilePhone0</MobilePhone>
            <BusinessPhone>BusinessPhone0</BusinessPhone>
            <WorkEmail>WorkEmail0</WorkEmail>
            <Fax>Fax0</Fax>
            <Smoker>Yes</Smoker>
            <BestTimeToCall>BestTimeToCall0</BestTimeToCall>
            <Occupation>Occupation0</Occupation>
            <Employer>Employer0</Employer>
            <Industry>Industry0</Industry>
        </Family_Client>
        <Family_Client>
            <ClientID>2147483647</ClientID>
            <Title>Mr</Title>
            <FirstName>FirstName1</FirstName>
            <LastName>LastName1</LastName>
            <MiddleName>MiddleName1</MiddleName>
            <PreferredName>PreferredName1</PreferredName>
            <Email>Email1</Email>
            <Gender>Male</Gender>
            <Dob>2006-05-04</Dob>
            <HomePhone>HomePhone1</HomePhone>
            <MobilePhone>MobilePhone1</MobilePhone>
            <BusinessPhone>BusinessPhone1</BusinessPhone>
            <WorkEmail>WorkEmail1</WorkEmail>
            <Fax>Fax1</Fax>
            <Smoker>Yes</Smoker>
            <BestTimeToCall>BestTimeToCall1</BestTimeToCall>
            <Occupation>Occupation1</Occupation>
            <Employer>Employer1</Employer>
            <Industry>Industry1</Industry>
        </Family_Client>
    </Family>
    <Family>
        <FamilyID>2147483647</FamilyID>
        <PostalAddress>
            <MailingAddress1>MailingAddress12</MailingAddress1>
            <MailingAddress2>MailingAddress22</MailingAddress2>
            <MailingCity>MailingCity2</MailingCity>
            <MailingPostCode>MailingPostCode2</MailingPostCode>
        </PostalAddress>
        <ClientAddress>
            <HomeAddress1>HomeAddress12</HomeAddress1>
            <HomeAddress2>HomeAddress22</HomeAddress2>
            <HomeCity>HomeCity2</HomeCity>
            <HomePostcode>HomePostcode2</HomePostcode>
        </ClientAddress>
        <Family_Client>
            <ClientID>2147483647</ClientID>
            <Title>Mr</Title>
            <FirstName>FirstName6</FirstName>
            <LastName>LastName6</LastName>
            <MiddleName>MiddleName6</MiddleName>
            <PreferredName>PreferredName6</PreferredName>
            <Email>Email6</Email>
            <Gender>Male</Gender>
            <Dob>2006-05-04</Dob>
            <HomePhone>HomePhone6</HomePhone>
            <MobilePhone>MobilePhone6</MobilePhone>
            <BusinessPhone>BusinessPhone6</BusinessPhone>
            <WorkEmail>WorkEmail6</WorkEmail>
            <Fax>Fax6</Fax>
            <Smoker>Yes</Smoker>
            <BestTimeToCall>BestTimeToCall6</BestTimeToCall>
            <Occupation>Occupation6</Occupation>
            <Employer>Employer6</Employer>
            <Industry>Industry6</Industry>
        </Family_Client>
    </Family>
</Nzfsg_Families>