Schema reuse : Salami Slice « XML Schema « XML Tutorial






File: Data.xml

<?xml version = "1.0" ?>
<Customer customerID = "242552">
   <Name>
      <FirstName>A</FirstName>
      <Middle>G</Middle>
      <LastName>C</LastName>
   </Name>
   <Address>
      <Street1>10 Place</Street1>
      <Town>D</Town>
      <City>E</City>
      <State>F</State>
      <Country>Australia</Country>
      <Postcode>2021</Postcode>
   </Address>
</Customer>

File: Data2.xml

<?xml version = "1.0" ?>
<Employee employeeID = "133">
   <Name>
      <FirstName>A</FirstName>
      <Middle>G</Middle>
      <LastName>B</LastName>
   </Name>
   <Address>
      <Street1>10 Place</Street1>
      <Town>small</Town>
      <City>big</City>
      <State>NS</State>
      <Country>Australia</Country>
      <Postcode>2021</Postcode>
   </Address>
</Employee>

File: Schema.xsd
<?xml version = "1.0" ?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
   
   <xs:element name = "Customer">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref = "Name" />
            <xs:element ref = "Address" />
         </xs:sequence>
         <xs:attribute name = "customerID" type = "integer" />
      </xs:complexType>
   </xs:element>
   
   <xs:element name = "Employee">
      <xs:complexType>
         <xs:sequence>
            <xs:element ref = "Name" />
            <xs:element ref = "Address" />
         </xs:sequence>
         <xs:attribute name = "employeeID" type = "integer" />
      </xs:complexType>
   </xs:element>
   
   <xs:element name = "Name">
      <xs:complexType>
         <xs:sequence>
            <xs:element name = "FirstName" type = "string" />
            <xs:element name = "Middle" type = "string" />
            <xs:element name = "LastName" type = "string" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   
   <xs:element name = "Address">
      <xs:complexType>
         <xs:sequence>
            <xs:element name = "Street1" type = "string" />
            <xs:element name = "Town" type = "string" />
            <xs:element name = "City" type = "string" />
            <xs:element name = "State" type = "string" />
            <xs:element name = "Country" type = "string" />
            <xs:element name = "Postcode" type = "string" />
         </xs:sequence>
      </xs:complexType>
   </xs:element>
   
</xs:schema>








3.98.Salami Slice
3.98.1.Salami Slice design Define global element declarations that are later referenced.
3.98.2.An XML Schema Document Using Named Type Definitions
3.98.3.Schema reuse
3.98.4.how XML Schema allows us to re-use names, and give them different content models.
3.98.5.extend the complex type that we have defined, creating new types for Customer and Employee:
3.98.6.Re-use in Text-only Element Content Models