Magazine
 
XML Schema

XMLSchema-instance”

you can use the schemaLocation attribute. This
attribute has two values. The first value is the
namespace to use. The second value is the
location of the XML schema to use for that
namespace:

xsi:schemaLocation=”http://www.roseindia.net note.xsd”

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

Feb 2008 | Java Jazz Up | 20
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF