Magazine
 
XML Schema

<To>Rohan</To>
XML-parsers-API
Feb-08 Java Jazz Up 21
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...</Body>
</E-mail>

Building blocks of a XML-Schema XSD - The <schema> Element

The <schema> element is the root element
of every XML Schema:

<?xml version=”1.0"?>
<xs:schema>
...
...
</xs:schema>

The <schema> element may contain some attributes like...

<?xml version=”1.0"?>
<xs:schema xmlns:xs=”http://http://
www.w3.org/2001/XMLSchema”
targetNamespace=”http://www.roseindia.net”
xmlns=”http://www.roseindia.net”
elementFormDefault=”qualified”>
...
...
</xs:schema>

The following code:

xmlns:xs=”http://www.w3.org/2001/ XMLSchema”

indicates that the elements and data types used in the schema come from the “http:// www.w3.org/2001/XMLSchema” namespace. It also specifies that the elements and data types that come from the “http://www.w3.org/2001/ XMLSchema” namespace should be prefixed with xs:

This code segment

targetNamespace=”http://www.roseindia.net”

indicates that the elements defined by this schema (E-mail, To, From, Subject, Body.) come from the “http://www.roseindia.net” namespace.

 

This fragment:

xmlns=”http://www.roseindia.net”

indicates that the default namespace is
“http:/ /www.roseindia.net”.

This fragment:

elementFormDefault=”qualified”

indicates that any elements used by the XML instance document which were declared in this schema must be a namespace qualified.

Referencing a Schema in an XML Document This XML document (E-mail.xml) has a reference to an XML Schema (E-mail.xsd).

<?xml version=”1.0"?>
<E-mail xmlns=”http://www.roseindia.net”
xmlns:xsi=”http://www.w3.org/2001/ XMLSchema”
x s i : s c h e m a L o c a t i o n = ” h t t p : / /
www.roseindia.net/Schema E-mail.xsd”>
<To>Rohan</To>
<From>Amit</From>
<Subject>Surprise....</Subject>
<Body>Be ready for a cruise...</Body>
</E-mail>

The following fragment:

xmlns=”http://www.roseindia.net”

Specifies the default namespace declaration. This declaration tells the schema-validator that all the elements used in this XML document are declared in the “http://www.w3schools.com” namespace.

Once you have the XML Schema Instance namespace available:

xmlns:xsi=”http://www.w3.org/2001/

Feb 2008 | Java Jazz Up | 19
 
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