XML Structure

The XML structure is hierarchical, with a structure of parent-child type, ie a parent element that will have child elements. These children in turn, are parents of other child elements, and so on.

XML example:

<?xml version="1.0" encoding="ISO-8859-1" ?> <messages>     <message>         <from>James</from>         <to>Peter</to>         <title>Meeting</title>         <text>Remember our meeting</text>     </message>     <message>         <from>John</from>         <to>Smith</to>         <title>Report</title>         <text>Create sales report</text>     </message> </messages>

Explanation of the example XML

The first part of the XML file is a statement of the version (version) and the character encoding that stores (encoding).

In the example, we have the following XML declaration line

<?xml version="1.0" encoding="ISO-8859-1" ?>

The version of the XML document will be 1.0

The encoding is ISO-8859-1, which is a codification Latin (LATIN-1), for example, to represent words with accents.

For English, use the UTF-8

In the example, there is a parent or root element of the document:


This name is user defined and can be any name, so, we can use to put a name indicative of the content you will have the XML file.

If your XML document contains invoice information, you can call <invoices>, if the document contains information from books, <books>.

Each parent element can have children or not.

In our example, the father <message>" has 2 child elements, <message>

First child of the parent (<items>) in our example:

    <message>         <from>James</from>         <to>Peter</to>         <title>Meeting</title>         <text>Remember our meeting</text>     </message>

Second son of the father (<items>) in our example:

    <message>         <from>John</from>         <to>Smith</to>         <title>Report</title>         <text>Create sales report</text>     </message>

Typically in an XML file is that the names of the first children to be equal, since XML files usually store lists of items with common information.

In turn, these child elements (<message>) are parents of other child elements (<from>, <to>, <title>, <text>).

And these child elements (<from> , <to> , <title> , <text>) may also have other children.

XML files are said to be self-defined, because the names of the labels often describe the content they carry.