XML :
Extensible Markup Language (XML) has been widely adopted as a platform-independent format for data representation.
Before getting deep into XML, a little introduction to the structure of XML.
Sample XML fragment:
<?xml version = "1.0" encoding = "UTF-16"?> <!—Student Information --> <Studentinfo> <Student> <StudentID>1</StudentID> <StudentName>Sathya</StudentName> <CourseID>1</CourseID> </Student> <Student> <StudentID>2</StudentID> <StudentName>Deepak</StudentName> <CourseID>2</CourseID> </Student> <Student> <StudentID>3</StudentID> <StudentName>sathish</StudentName> <CourseID>3</CourseID> </Student> </Studentinfo>
In the above sample XML fragment ,
<Studentinfo> is the root node
<Student> is the element node,so in the above XML fragment,we havee 3 element nodes.
<StudentID> ,
<StudentName> ,
<CourseID> .. are the attribute nodes
1,sathya,1,.. are the attribute values.
<Student> is the start tag & </Student> is the end tag of the element node.
Similarly,
<Studentinfo> is the start tag & </Studentinfo> is the end tag of root node.
To put it simple in database terminologies,consider
root node as the database name,element node as the table name,attribute node as column name & attribute values as column values.
<!—Student Information --> are XML comments denoted by <!-- and --> delimiters
<?xml version = "1.0" encoding = "UTF-16"?> are XML processing instructions marked by <? and ?> delimiters.
A processing instruction is a means to provide additional metadata to a processing application.
FOR XML clause:
For getting relational data in the form of XML, FOR XML clause was introduced.
Using FOR XML clause,we can represent relational data in the form of XML in two ways:
1.) Attribute Centric
2.) Element Centric
1.) Attribute Centric
2.) Element Centric
/*******************************Sample data ***********************************/
Let us create sample datas for all below XML examples: