Total members 11835 |It is currently Sun Sep 27, 2020 5:05 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





XSD Complex elements :

XSD Complex element contains other elements and attributes .


How to define complex elements:

For example the following XML file:
Code:
<student>
<name>Jozef samir</name>
<age>32</age>
</student>

<xs:element name="student">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:long"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>


You define it by another way:
Code:
<xs:element name="student" type="studentType" >
  <xs:complexType name="studentType" >
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:long"/>
    </xs:sequence>
  </xs:complexType>


The difference between the two ways, in the first method you can only create one element of this complex type, but in the second way, you can define many elements using the same type.
For example :
Code:
<xs:element name="student" type="studentType" >
<xs:element name=" professor  " type="studentType" >


  <xs:complexType name="studentType" >
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:long"/>
    </xs:sequence>
  </xs:complexType>



Note: <xs:sequence> Tag means element should appear in same order in XML document.

2. XSD Complex Type extension:
You can extends the complex type and add more elements to it.
Code:
<xs:element name="student" type="studentType" >
  <xs:complexType name="studentType" >
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="age" type="xs:long"/>
    </xs:sequence>
  </xs:complexType>

<xs:complexType name="moreinfo">
  <xs:complexContent>
    <xs:extension base="studentType">
      <xs:sequence>
        <xs:element name="address" type="xs:string"/>
        <xs:element name="city" type="xs:string"/>
        <xs:element name="country" type="xs:string"/>
      </xs:sequence>
    </xs:extension>
  </xs:complexContent>
</xs:complexType>





_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : lesson5: XSD Complex elements
 lesson6: XSD Complex Empty Elements     -  
 lesson7: XSD Complex Text-Only Elements     -  
 Complex Numbers     -  
 Complex numbers calculator (C++)     -  
 solve the complex numbers and do operations on it     -  
 lesson9: XSD Complex Types Indicators     -  
 lesson8: XSD Complex Type Mixed Content     -  
 Add elements to the end of an array     -  
 Elements of a Java Program     -  
 clone arrayList elements     -  



Topic Tags

XSD Elements
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com