2015-06-17 122 views
2

這裏我有我的XML模式。我試圖確定Family_Client是否允許多個客戶端,因爲Family表可能有多個家庭成員。在XML中添加多個元素

<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子元素或者是有別的東西,我需要做什麼?

回答

3

在一個序列中,可以重複maxOccurs> 1的任何元素。根據您的代碼1至10 <Family_Client />元素將被允許。如果您希望允許無限數量的家庭客戶端,也可以將該屬性更改爲maxOccurs =「unbounded」。

+0

酷感謝您,只是我正在尋找的答案。 –

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>