Total members 11894 |It is currently Thu Nov 21, 2024 10:56 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>


This is XML defines a "student" element which contains two child elements: "name" and "age". The "name" element is of type "xs:string", which means it can hold a string value, and the "age" element is of type "xs:long", which means it can hold a long integer value. It also defines the structure of the elements, with xs:element and xs:complexType, which defines a complex type element, which can contain other elements and attributes. It also specifies the structure of the elements and attributes, using xs:sequence, which says that the elements should appear in a specific sequence. The name "Jozef Samir" and the age "32" are the values of the elements.



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 the same order in an XML document.

2. XSD Complex Type extension:
You can extend 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>


This is also an example of XML code, which defines a "student" element of type "studentType". The "studentType" is defined as a complexType, which contains two child elements, "name" and "age", both of type "xs:string" and "xs:long" respectively. This code also defines an additional complexType named "moreinfo" which is an extension of studentType. It uses xs:extension, which allows a complexType to inherit the elements and attributes of another complexType. The "moreinfo" complexType contains additional elements "address", "city" and "country" of type "xs:string". The xs:sequence element indicates that these elements should appear in a specific order. This code defines a more complex structure for the student element, which includes not only the basic information of "name" and "age" but also more information like "address", "city", "and country".



_________________
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     -  
 count elements in a vector     -  
 Elements of a Java Program     -  



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