Total members 11890 |It is currently Thu Apr 25, 2024 10:52 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





<schema> Element :
All XML schema have a common element which is <schema> .<schema> element is the root of your XSD schema.

It looks like this :
xml code
<?xml version="1.1"   encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.codemiles.com" xmlns="http://www.codemiles.com" >
<!-- other elements here -->
</xs:schema>

This is an XSD code that defines the structure and the data types of an XML document. The first line <?xml version="1.1" encoding="UTF-8"?> is the XML declaration, it specifies the version of XML used in the document and the character encoding of the document. The second line <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" is the root element of the schema, it defines the namespace of the schema; in this case, it's "http://www.w3.org/2001/XMLSchema", it's the standard namespace of the XML schema. The next line targetNamespace="http://www.codemiles.com" defines the target namespace of the schema; this is the namespace that will be used in the corresponding XML document. The last line xmlns="http://www.codemiles.com" is a default namespace that will be used in the corresponding XML document. This XSD code only defines the schema's basic structure, and no elements or types are defined in it. For the XSD to be useful, it must contain elements and types that describe the structure of the XML document it will use.


Let us understand what the meaning of the urls and namespaces in the xml schema is:

1.
Code:
xmlns:xs="http://www.w3.org/2001/XMLSchema"

This means that the datatypes and elements used in this schema come from this namespace, and it should be prefixed with "xs".

2.
Code:
targetNamespace="http://www.codemiles.com"

The new elements defined in this schema come from this namespace URL.

3.
Code:
xmlns="http://www.codemiles.com"

Default namespace, used if you didn't find the first one.


Once you create your XML schema, you can generate an XML file and put a link to its XML schema as a reference in validation. For example :
xml code
<?xml version="1.0"?>

<school xmlns="http://www.codemiles.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.codemiles.com school.xsd">

<Name>School number 1</Name>
<Location>Near train station</Location>
<Size>1000m'2 </Size>

</school>


As you may have noticed :
Code:
xsi:schemaLocation="http://www.codemiles.com school.xsd"


Used as a reference to your XML schema.

This is an XML document that describes a school. The first line <?xml version="1.0"?> is the XML declaration, it specifies the version of XML used in the document. The next line <school xmlns="http://www.codemiles.com" is the root element of the XML document, it defines the namespace of the document, and in this case, it's "http://www.codemiles.com". The next line xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" defines the namespace used for the XML Schema instance. This is a standard namespace used to indicate that the document is associated with an XSD schema. The next line xsi:schemaLocation="http://www.codemiles.com school.xsd" is an attribute that associates the XML document with an XSD schema, it specifies the location of the XSD schema that is used to validate the document. The next lines <Name>School number 1</Name>, <Location>Near train station</Location>, <Size>1000m'2 </Size> are the elements of the document. These elements contain information about the school, such as its name, location, and size.



_________________
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 : lesson1 : <schema> Element
 define UUID in your XSD schema     -  
 Pop the element off the end of array     -  
 Usage of big element tag.     -  
 Array element navigation     -  
 access element in array C++     -  
 print element in 2d matrix     -  
 lesson2 : XSD simple element     -  
 UnSet array element     -  
 Get the position of HTML element using JQuery     -  
 How to make html element hidden using CSS     -  



Topic Tags

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