Most Valuable Professional


View Jan Karel Pieterse's profile on LinkedIn subscribe to rss feed
Subscribe in a reader

Subscribe to our mailing list

* indicates required

File crashes Excel!!

Save my workbook!
The best tool for salvaging problematic workbooks.

Trainings

Excel VBA Masterclass (English)
Excel VBA for Financials (Dutch)

Third party tools

Speed up your file

FastExcel
The best tool to optimise your Excel model!

Repair your file

Stellar Phoenix Excel Repair
Best tool to repair corrupt Excel sheets and objects
Home > English site > Articles > XML and Excel > Structure of XML
Deze pagina in het Nederlands

XML and Excel

Structure of an XML file

The XML code shown in figure 1 (shown again below) is relatively easy to read and understand (file test_en.xml in the download).


XML file shown in Internet Explorer

The first (blue) line indicates we're dealing with an XML file. This line should appear in each XML file. The file contains both information and pairs of opening and closing tags around the information. A set of opening and closing tags and the information in-between is called an element. The text below shows a complete element:

<name>Joe Jackson</name>

The XML example shown above thus contains the following named elements:

companies, company, companyname, employee, code, name, street, houseno, areacode, place, phone.

Tag names are case sensitive, "name" is not the same as "Name". A tag is characterized by text surrounded by less than and greater than symbols: <tag>. Each tag must have a closing tag: </tag>. All text between the closing and opening tags belongs to the tag.

If there is no content between the tags we can combine opening and closing tag into one self-closing tag: <tag/>. This is done when either there is no content, or when the content of a tag is given as an attribute of the tag, for example::

<name name="Jan Janssen"/>

is equivalent to

<name>Jan Jansen</name>

The use of attributes really doesn't improve readability and it is recommended to use paired opening and closing tags instead.

The second line of the XML file contains the starting tag of the root element: <companies>. The element "companies" is the so-called Root element of the XML file. Each XML file must contain exactly one root element. Compare an XML file with a tree: a tree has exactly one stem. If there is more than one stem, we have a bush, not a tree.

Next, line 3 indicates the start of the element "companies". Within this "companies" element, multiple "company" elements may be nested.
Line 4 shows the entire "companyname" element, after which lines 5 to 27 contain data of the three employees of company "Stanford and Son".

The power of XML is that in order to understand the data structure and intent of an XML file, all you have to do is have a look at the file. Also, you can imagine adding a new company to this file, along with a couple of employees is simple.


 


Comments

All comments about this page:


Comment by: satpal (10/16/2010 9:16:38 PM)

we want to upload the excise dealer return in xml format but excise system (aces) remarks that your xml file structure is damaged.please guide us what should we do.

thanks

regards

satpal
(9811055427)

 


Comment by: Jan Karel Pieterse (10/17/2010 5:15:44 AM)

I expect it means that the XML file is missing something. Either the structure of the xml file does not adhere to the rules that each tag needs an opening and a closing part or the order of the opening and closing tags isn't correct.
Also, not everything is allowed as values between tags, maybe some characters need to be escaped.

 


Comment by: vietthufet (6/10/2013 6:35:11 AM)

this article really usefull for me. I'm starting work on XML file

 


Have a question, comment or suggestion? Then please use this form.

If your question is not directly related to this web page, but rather a more general "How do I do this" Excel question, then I advise you to ask your question here: www.eileenslounge.com.

Please enter your name (required):

Your e-mail address (optional but if you want me to respond it helps!; will not be shown, nor be used to send you unsolicited information):

Your request or comment:

To post VBA code in your comment, use [VB] tags, like this: [VB]Code goes here[/VB].