XML Elements & content



Elements & Content : XML Document

In the last chapter we have seen different optional parts of XML document. In this chapter we are going to learn different mandatory fields of XML document.

Explanation :

Consider this example -

<Student>
  <Boy>
    <name>Pritesh</name>
    <marks>90</marks>
  </Boy>
  <Girl>
    <name>Pooja</name>
    <marks>89</marks>
  </Girl>
</Student>

In the above example -

1. Root Node

<Student>

2. Sub Nodes

<Boy> and <Girl>

are siblings of each other and Children nodes of <Student>

3. Sub-Sub Nodes

<name> and <marks>

Again for Each <Boy> and <Girl> have two child nodes.

XML Tree Structure :

XML Tree Structure of Document

Alternate Way for Above XML Document :

<Student>
  <Boy name="Pritesh" marks="90"></Boy>
  <Boy name="Pooja" marks="89"></Boy>
</Student>

Root Element :

  1. Each XML Document must have One and Only One Root Element.
  2. Other XML elements must be Nested inside Root Element.
  3. Opening Tag of Root Element is the Opening Tag of Document.
  4. Closing Tag of Root Element is the Closing Tag of Document.

Some Facts :

  1. XML is Organized as Tree Structure.
  2. XML can have User Defined Tags.
  3. XML consists of any number of nodes.

Elements & Content

Root element opening tag
<Person>
Child elements and content
<Student>
  <Boy>
    <name>Pritesh</name>
    <marks>90</marks>
  </Boy>
  <Girl>
    <name>Pooja</name>
    <marks>89</marks>
  </Girl>
</Student>
Root element closing tag
</Person>