Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

Features

Technology
  Tech. Home
  GPS
  OSI
  WiMAX
  VoIP
  WiFi
  HSDPA
  LBS
  Vehicle Tracking
  SCADA
  Tech. What is?
Jobs At RoseIndia.net!
 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

XSD Simple Elements

                         

XML Schemas define the elements of  XML files.

 XML  simple element contains only text not even any other elements or attributes.But the text can be of many different types. It can be among the types included in the XML Schema definition (boolean, string, date, etc.), or it may be a custom type that a user is free to define. Even. restrictions (facets) can be added  to a data type in order to limit its content.

Defining a Simple Element

The syntax for a simple element is:

<xs:element name="aaa" type="bbb"/>

where aaa is the name of the element and bbb is the data type of the element.

XML Schema has a lot of built-in data types. The most common types are:

  • xs:string
  • xs:decimal
  • xs:integer
  • xs:boolean
  • xs:date
  • xs:time

Example:

Few of  XML elements:

<name>Rahul</name>
<age>15</age>
<currentdate>2007-05-15</currentdate>

The corresponding simple element definitions:

<xs:element name="name" type="xs:string"/>
<xs:element name="age" type="xs:integer"/>
<xs:element name="currentdate" type="xs:date"/> 

Default  Values for Simple Elements

Simple elements may have a specified default value OR a fixed specified value .A default value is automatically assigned to the element when no other value is specified for example to set the "orange" default value .

<xs:element name="fruit" type="xs:string" default="orange"/>

Fixed Values for Simple Elements

A fixed value is also automatically assigned to the element, and it  cannot further specify another value.

In the following example the fixed value is "apple":

<xs:element name="fruit" type="xs:string" fixed="apple"/>

XSD Complex Elements:

A complex element contains other elements or attributes.

What is a Complex Element?

It is an XML element that contains other elements and/or attributes. They are of four types:

  • empty elements
  • elements that contain only other elements
  • elements that contain only text
  • elements that contain both other elements and text

Note: Each of these elements may contain attributes as well!

Examples of Complex Elements

A complex empty XML element, "employee"

<employee eid="1234"/>

A complex XML element, "employee", which contains only other elements:

<employee>
<firstname>Amit</firstname>
<lastname>Gupta</lastname>
</employee>

A complex XML element, "employee", which contains only text:

<employee type="category">Programmer</employee>

A complex XML element, "event", which contains both elements and text:

<event>
It occured on <date lang="norwegian">15.05.07</date> ....
</event>

Defining a Complex Element:

Look at this complex XML element, "employee", which contains only other elements:

<employee>
<firstname>Amit</firstname>
<lastname>Gupta</lastname>
</employee>

We can define a complex element in an XML Schema in two different ways:

1.  "employee" element can be declared directly by naming the element, 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>

In the above described method only "employee" element can use the specified complex type. Note that the child elements, "firstname" and "lastname", are surrounded by the <sequence> indicator. This means that the child elements must appear in the same order as they are declared.

2.  "employee" element can have a type attribute  refering to the name of the complex type to use:

<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>

 Using the method described above, several elements can refer to the same complex type, like this:

<xs:element name="employee" type="personinfo"/>
<xs:element name="employer" type="personinfo"/>
<xs:element name="teammember" 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>

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.