XMLSCHEMA

XML SCHEMA Interview Questions And Answers

More interview questions and answers

What is XML Schema?

 When we don\'t want to use DTD than we can use XML Schema as an alternative of DTD.

Using XML Schema we can describe the structure of XML document.We can also called XML Schema language as XML Schema Definition.Some main of XML Schema are given below:

1. We can define the child element among the elements.

2. XML Schema also define order and number of child element.

3. Using XML Schema we can define data types, default and fixed values for attributes and elements. XML Schema has W3C Recommendation since 02 May 2001.

How we can say XML Schemas are successors of DTDs?

 Because of some reasons we can say that XML Schemas area successors of DTDs.

Some reasons are given below: 

1. As DTD, XML Schemas also written in XML. 

2. As DTD, XML Schemas also support Data types and namespaces. 

 But, XML Schemas is much good as DTDs. 

Because it is much richer and powerful than DTDs. And it also has some features that are made to solve problems comes in future.

Why we use XML Schemas?

 I have given you some main reasons those made XML Schemas more powerful than DTD.

1. Using XML Schemas we can describe permissible document content more easily.

2. Using XML Schemas we can validate the rightness of data easily.

3. Using XML Schemas we can work with data that comes from database more easily.

4. Easy to switch data b/w different datatypes.

5. Easy to define data formats and to made restrictions on data.  

Explain why XML Schemas are Estensible?

 I have given you some reasons that say XML Schemas are extensible.We can Reuse our XML Schemas with in other XML Schemas.Also we can made our own data types which are derived from standard types.We can Refer multiple schemas in an same XML document. 

How you define elements of XML document in an XML Schema?

 Simple I given you a example of an XML document. Than I told you define elements of this XML document in an XML Schema.
Example shows a XML Document.


Abhi
Sudhi
Birthday Wish
Happy Birthday Dear

 Now, I will show you how to define these elements(to, from, heading, body)of XML document(saved with "note.xml")in an XML Schema (saved with "note.xsd").




 
   
     
     
     
     
   
  
 

 

How you define complex and simple type of element?

 In an XML Schema element are of two types.
1. Complex Type Element
2. Simple Type Element
1. Complex Type Element: Complex Type Elements are elements those contain elements.
2. Simple Type Element: Simple Type Elements are elements those doesn't contain any other elements.
 I explain you complex and simple type of element with an example: 


Abhi
Sudhi
Birthday Wish
Happy Birthday Dear

 In the above example note element called as complex element because it contains elements(to, from, heading, body).And element to, from, heading and body called as Simple Type Element because it doesn't contain any other element. 

Give an example shows XML document has a reference to an XML Schema?

This example show you how XML document has a reference to an XML Schema.
Example:


xmlns="http://www.r4r.co.in"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.r4r.co.in note.xsd">

Abhi
Sudhi
Birthday Wish
Happy Birthday Dear

How you use Schema Element in XML Document?

 We can say that  element is an root element in XML Schema.
 Now, I given you syntax of an XML Schema.
Syntax:


   ....
   ....

 Yes, Schema element can also contain attribute.
Example:


   ....
   ....

 In the above example "http://www.w3.org/2001/XMLSchema" namespace use to show us datatype that we used in this XML Schema.

targetNamespace="http://www.r4r.co.in" is used to define elements(note, to, from, heading, body)  comes from http://www.r4r.co.in namespace in this XML Schema.

xmlns="http://www.r4r.co.in" is used to show the default namespace.

elementFormDefault="qualified"> use to show that all element that we used by XML instance document has qualified namespace. 

 

What do you mean by Simple Element?

I have already told you XML Schema has define elements in two types.
1. Simple Element
2. Complex Element

 Simple Element: In XML simple elements are those element that has contain only text doesn't contain any other elements or attributes.
Text may be of any type that define in XML Schema
like boolean,string,date etc.
Syntax:


 where, abc is used to define name of element and xyz is used to define data type of element.

Which data types we used in XML Schema?

 XML Schema has many build-in data types.I have given you some common data type that we used in XML Schema.
xs:integer, xs:decimal, xs:boolean, xs:string, xs:time, xs:date

 Now, I have example which show you how to use these datatypes in XML Schema. 

Shredi
46
1963-02-03
120.76


 Now, I will show you simple element definitions of these elements.



 
 

How you set default and fixed values for Simple Elements?

 First I told you the mean of default and fixed value.
 Default values are those values that are directly assign to element when this element doesn't contain any other defined value.
Example:


 In the above example default value of color is "yellow". 

 Fixed values are those values that are directly assign to element but it doesn't contain any other defined value for this element.
Example: 


In the above example fixed value of color is "yellow". 

How you define attributes in XML Schema?

 You have to note this in XML Schema all attributes are only declare as simple types element not as complex types.Because yes, Simple Elements has no attributes and attributes are only happen with Complex Elements.But key point is that in XML Schema always attribute declare as simple type itself.
Syntax:


 where,abc and xyz are called as name and data type of the attribute respectively.

How you set Default and fixed values for attributes?

  Mean of default and fixed value interms of attributes. 
Default values are those values that are directly assign to attribute when this atribute doesn't contain any other defined value.
Example:

 In the above example default value of lang is "EN".
  Fixed values are those values that are directly assign to attribute but it doesn't contain any other defined value for this attribute.
Example:
 
In the above example fixed value of lang is "EN".

How you define optional and required attributes?

 In XML Schema their is no need to set attribute as optional.Because it is by default optional.
 You can define attribute is required.Than you define this by using "use" attribute.
Example:



XML SCHEMA Interview Questions And Answers