Introduction to XML Tags
XML Extensible Mark-up Language tags are completely different from HTML tags in a way that they do not have predefined tags instead XML Launches user-defined tags and is named to be a recognizable feature of XML. With XML, Tags are the basic foundation and are defined as the scope of an element. To indicate which element belongs to the respective content the tags are been introduced. Here users have to create their own tag according to their specifications also all the tags specified should match with the end tag. To be clear, XML tags are user-defined mark-up language. XML tags are defined using Schemas or Document Type Definition (DTD) specifically and considered to be extensible tags.
XML tag starts with (“<“) character and ends up with (“>”) characters used to state the start and close of the elements, but it is not a part of the element. And everything that is done between the start and end tag is exclusively termed as content. The content of the elements is determined openly which may be in character data, element, or comment. As we go along, we are allowed to make new XML tags. Tags in Xml part is case- sensitive which means <Location>, <LOCATION> </location> both the tags are entirely different and does different purpose in XML file. as lower-case and upper-case content is different in element names. Precisely we should be very consistent with respect to one element.
With respective to tags in they have some properties which are listed below:
Properties of XML Tags
Below is the properties 0f XML Tag:
1. Every document in XML should have a particular root tag and can be named with any user-defined tag and should be closed with the correct root tag name.
<Hospital> <patient> <patient name>lousis Dawn </patient name> </patient> <date> " 29- 10-2019 " </date> </Hospital>
In the above statement, it creates the smallest XML document. Meanwhile, <Hospital> is a root tag in the XML document. We shall see the illustration with the tree. The above example has three elements. The X-tree is drawn from the above example.
2. The start tag or open tag should have the same name as the end tag.
3. As mentioned above the tags are case-sensitive mandatorily.
4. The order of closing the tag is noticeable, the outer tag should be closed after the inner tag.
<root> <child> <sub child> </sub child> </child> </root>
XML has three types of tags. They are:
- Open Tag
- Close Tag
- Empty Tag
1. Open / Start Tag
The start tag denotes the start of any non-empty XML element in an Xml file and continues with the text content and other elements. Always note that the element name should start immediately after the “<” character also most importantly blank spaces and tabs are not allowed between the elements. How about the element names inside the tag? yes, they do have some criteria like the first and second characters cannot be numerals, periods but can be alphabets and underscore (_).
<mobile1> 99995555 </mobile1> // numerals are used at the last.
<1abc> britt </1abc> // as Numerals can’t be a first character.
The content used in between the tags can be any alphanumeric characters.
The below example highlights the tag to give the difference between the text.
<employee> Suchitra Ben </employee> <age> 23 </age> <dob> August 21 </dob>
Even attributes are used within the tags which are declared with (=””). With XML the values of the attributes should not omit the quotation marks. Improper nesting of tags is not allowed in XML and doesn’t make good sense in the code. Sample code is shown below.
<Supermarket> <product category="children"> <pname>Pediacure </pname> <Mfd>2005</Mfd> <price>39.54</price> </product> </Supermarket>
2. Close Tag / End Tag
Once we start with the start tag it is mandatory to end up with an end tag which is illustrated below. In xml, the closing tag must be closed by default not like html.Same like start tag end tag should not be described with blank space after the character “/”.
<PersonalInfo> <Fullname>Jane Smith</Fullname> <Organization>L & T</Organization> <mobile>(412) 666-4762</mobile> </PersonalInfo>
3. Empty Tag
Any tag which doesn’t have content in between the tag is considered to be an
Empty tag. In layman terms, leaving out the description part of the element is done by a simplified tag named empty tag. It can be applied in two ways: One starting with <and ends with /> by a single element.
Full-fledged syntax of empty tag is given below:
The character “/ “at the end of the tag tells the XML parser that the element in the tag begins and ends here. This is a flexible shorthand implementation to use mark up empty elements simple and easy.
Below are the examples of XML Tags:
<?xml version="1.0" encoding="UTF-8"?> <toystore> <toy category="SoftToys"> <title lang="en">twinkle</title> <authorname>De Morgan</authorname> <year>2012</year> <price>70.00</price> </toy> <toy category="Vehicle"> <title lang="en">Wheels on the bus</title> <authorname>Johnson Brit</authorname> <year>2010</year> <price>55.00</price> </toy> <toy category="MusicalToys"> <title lang="en">Baby Shark</title> <authorname>Chris Paul</authorname> <year>2014</year> <price>100.00</price> </toy> </toystore>
In the above code <toystore> is the root node followed by child tags.
<?xml version="1.0" encoding="UTF-8"?> <pass>One Adverisement.</pass> <hr></hr> <hor>This is another Advertisement which is good compared to the second one.</hor>
Use of <hr> tag separates the content doesn’t wrap the whole content.
Conclusion – XML Tags
Coming to the end, above we have described this article which gives a basic explanation of XML tags and elements. By this one could be read and understand the working of XML documents in the browser with an example in a simple and well-defined path. We have seen in all the examples that the designer of the XML document has used the name of the element as per their requirements.
This is a guide to XML Tags. Here we discuss the introduction to XML Tags and their Properties along with their types. You can also go through our other suggested articles to learn more –
- Kafka Alternatives | Top 5
- RabbitMQ vs Kafka – Top differences
- Introduction to Kafka Tools
- 10 Best Kafka Interview Questions