Understanding XML

XML, like JSON, is a hierarchical data format that allows a nested data structure. If you have worked with HTML before, you might be familiar with the general structure and syntax of XML, which HTML is based on.

An XML dataset consists of a nested tree of elements where each element may contain text with a particular value, another element or a collection of additional elements. Each element in the tree may also contain any number of attributes which describe the element.

Each element is represented by an opening tag and a closing tag. An opening tag indicates the beginning of an XML element. It is written by writing the name of the tag inside angle brackets. The following is what an XML opening tag looks like:

<tagname>

A closing tag follows the opening tag and indicates the end of an element. It is written by specifying the name of a tag inside angle brackets with a / before the name. The following is what an XML closing tag looks like:

</tagname>
In other parts of the book, angle brackets are used as a placeholder for some value or parameter. In the previous examples, and when displaying XML in general, the angle brackets are meant literally, as they are a part of the XML syntax. 

The attributes of an element are written inside the opening tag. An attribute is specified with the attribute name follow by an = symbol followed by the value of the attribute inside " characters. The following is what the opening tag of an element with attributes looks like:

 <tagname attribute1="value1" attribute2="value2">

Finally, the nested elements within an XML element are written between the opening and closing tags of the parent element. To make this human readable, the nested elements are typically written on separate lines with additional levels of indentation.

The following is an example of what a typical XML document might look like:

<XMLdocument>
<metadata>
<timecreated>
5:00 AM
</timecreated>
</metadata>
<dataformats>
<dataformat type='hierarchical'>
JSON
</dataformat>
<dataformat type='hierarchical'>
XML
</dataformat>
<dataformat type='tabular'>
CSV
</dataformat>
<dataformats>
</XMLdocument>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset