Elements are the basic building blocks of an XML document.
Following are the basic characteristics of XML Elements
<html> <body> <head> <title>w3resource-xml</title> </head> <body> <p><b>This is w3resource.com.</b>The largest tutorial on web based development.</p> <p>We are learning <i>xml</i></p> </body> </html>
example xml file:
<?xml version="1.0"?> <world> <continents> There are five continents </continents> </world>
The element world has a child element continent in this example. Note that the element continent is started and finished within the opening tag<world> and closing tag </world> of the element with tagname world, which is the parent of the continents element.
In the following example, loss element does not have any content. So it is being written as <loss></loss>
<?xml version="1.0"?> <series> <loss> </loss> </series>
But writing it like the following is also allowed:
<?xml version="1.0"?> <series> <loss /> </series>
This is referred as empty element shorthand.
<?xml version="1.0"?> <W3RESOURCE> This is the largest online tutorial on web development </w3resource>
But this is the correct use
<?xml version="1.0"?> <w3resource> This is the largest online tutorial on web development </w3resource>
|<3topic3></3topic3>||Incorrect since elements are begin with invalid characters|
|<three,topic3></three,topic3>||Incorrect since elements contain invalid characters|
|<three;topic3></three;topic3>||Incorrect since elements contain invalid characters|
|<three_topic:topic3></three_topic:topic3>||Incorrect, reference to undeclared namespace prefix|
|<!topic></ !topic>||Will generate error since the declaration has an invalid name|
|<[topic]></[topic]>||Will generate an error that complains that an element began with an invalid character.|