XML Samples and Examples
In this guide, we will see few examples of XML document.
Simple XML document example
This is a simple XML document. You can understand the data, by just looking at the document. We have used self-describing tags.
A Song of Ice and Fire
George R. R. Martin
English
Epic fantasy
The first line
is called XML Prolog. It is optional, however when we include it in the XML document, it should always be the first line of the document. XML Prolog defines the XML version and the encoding used in the XML document.
The tag
is the root of this XML document. A XML document should always have a root element and at the end of the document this root element needs a closing tag, just like that we have used in the above example.
The tags
, , and are the child elements of the root element
. We will discuss more about these in the XML syntax tutorial.
Based on the above discussion we can say that a XML document structure looks like this:
.....
XML Example – Student data
Lets take a look at the another example of XML. In this XML document we have the details of the few students. Here is the root element, is the child element and name, age, subject and gender are sub-child elements.
Rick Grimes
35
Maths
Male
Daryl Dixon
33
Science
Male
Maggie
36
Arts
Female