XSD composite Elements

Source: Internet
Author: User

XSD-qualified xsd empty element

a composite element contains additional elements and/or attributes. What is a composite element.

A composite element is an XML element that contains other elements and/or attributes. There are four types of composite elements: an empty element containing elements of elements and text that contains only elements of other elements of the element that contain text

Note: All of the above elements can contain attributes. examples of composite elements

The composite element, "product", is empty:

<product pid= "1345"/>

Compound element, "employee", contains only the other elements:

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>

Compound element, "food", contains only text:

<food type= "Dessert" >ice cream</food>

Composite elements, "description", contain elements and text:

<description>
It happened on <date lang= "Norwegian" >03.03.99</date> ....
</description>
How to define a composite element.

See this composite XML element, "employee", which contains only the other elements:

<employee>
<firstname>John</firstname>
<lastname>Smith</lastname>
</employee>
in the XML Schema, we have two ways to define composite elements:

1. By naming this element, you can declare the "employee" element directly, just like this:

<xs:element name= "Employee" >
  <xs:complexType>
    <xs:sequence>
      <xs:element name= " FirstName "type=" xs:string "/>
      <xs:element name=" LastName "type=" xs:string "/>
    </xs:sequence >
  </xs:complexType>
</xs:element>

If you use the method described above, only "employee" can use the specified compound type. Note that its child elements, "FirstName" and "LastName", are enclosed in indicator <sequence>. This means that the child elements must appear in the order in which they are declared. You'll learn more about indicators in this section of the XSD indicator.

2. The "employee" element can use the type attribute, which is used to refer to the name of the composite type to be used:

<xs:element name= "Employee" type= "Personinfo"/>

<xs:complextype name= "Personinfo" >
  <xs: sequence>
    <xs:element name= "FirstName" type= "xs:string"/>
    <xs:element name= "LastName" Type= "XS : string "/>
  </xs:sequence>
</xs:complexType>

If you use the method described above, then several elements can use the same composite type, such as this:

<xs:element name= "Employee" type= "Personinfo"/>
<xs:element name= "student" type= "Personinfo"/>
<xs:element name= "member" type= "Personinfo"/>

<xs:complextype name= "Personinfo" >
  <xs: sequence>
    <xs:element name= "FirstName" type= "xs:string"/>
    <xs:element name= "LastName" Type= " Xs:string "/>
  </xs:sequence>
</xs:complexType>

You can also base a composite element on an existing composite element, and then add elements like this:

 <xs:element name= "employee" type= "Fullpersoninfo"/> <xs:complextype name= "Personinfo" > <xs: sequence> <xs:element name= "FirstName" type= "xs:string"/> <xs:element name= "LastName" Type= "Xs:string" /> </xs:sequence> </xs:complexType> <xs:complextype name= "Fullpersoninfo" > <xs: complexcontent> <xs:extension base= "Personinfo" > <xs:sequence> <xs:element name= "Addre SS "Type=" Xs:string "/> <xs:element name=" City "type=" xs:string "/> <xs:element name=" Country "t Ype= "xs:string"/> </xs:sequence> </xs:extension> </xs:complexContent> </xs:complextype 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.