Sunit Katkar's Home Page

 Tutorials:
 

A simple XML Resume example

If you have read the introduction to XML then lets look at how we can use XML to structure information about a resume.

A well formed XML document has the following:

  • a Prolog - instructions for the parser for processing the actual document
  • the Document itself - contains one root element and other sub-elements and nested elements
  • an Epilog - this is optional and can have some more information about the document.

Some of things you should note before you proceed. This is not an exhaustive list, but nevertheless this will suffice for now.

  • All tags in an XML document should be properly closed unlike HTML where you may omit some closing tags like </P> and the browser would still forgive you and render the document properly.
  • Tags are case-sensistive. For example <Name> and <name> and <NAME> are three different tags
  • A XML tag may or may not have a atrribute. Like <EMPLOYEE TYPE= "Regular">
  • Every document must have a XML Declaration or a Document Type Declaration so that the parser knows that this is a XML document
  • There is usually a Document Type Definition (DTD) associated with every XML document. This is a special file or block of text within an XML document which has the special grammar rules for the document.
  • Your XML document can be valid without having a DTD associated with it. As long as your document has ben created applying all the XML rules as per the standards, you can be pretty sure that it is a well formed document. We will see later on how to check the validity of a XMl document with an associated DTD

Note: Do not mistake Document Type Declaration with Document Type Definition (DTD). A document type declaration is simply a declaration that this is a XML document and what version of XML you are using. A simple declaration with the bare essential attributes is like this - <?xml version="1.0" ?>

Okay now lets dive straight into our first XML document. There is so much more information about the structure of an XML document, Document Type Declaration and Document Type Definitions, etc. I cannot cover all of that here as it would simply entail writing a whole book about it :) I have added comments wherever possible and hope they should suffice. So on we go.

A very basic XML document for our resume example.


 <?xml version="1.0" ?>
 <!-- This line here is a Prolog. More correctly it tells that this is a XML document -->
 
 <!-- now lets look at the Document itself -->
<CANDIDATE><!-- the root element -->
 <CANDIDATE_INFO>
    <NAME>
        <FIRST_NAME>Sunit</FIRST_NAME>
        <LAST_NAME>Katkar</LAST_NAME>
    </NAME>
    <CONTACT_INFO>
        <EMAIL>sunitkatkar@hotmail.com</EMAIL>
        <PHONE>555-123-4567</PHONE>
    </CONTACT_INFO>
    <SKILLS>
        <SKILL>
          <LANGUAGE>ASP</LANGUAGE>
          <EXPERIENCE>4 years</EXPERIENCE>
        </SKILL>
        <SKILL>
          <LANGUAGE>PHP</LANGUAGE>
          <EXPERIENCE>1 year</EXPERIENCE>
        </SKILL>
        <SKILL>
          <LANGUAGE>Javascript</LANGUAGE>
          <EXPERIENCE>4 years</EXPERIENCE>
        </SKILL>
    </SKILLS>
 </CANDIDATE_INFO>
 <CANDIDATE_INFO> <!-- lets have one more candidate -->
    <NAME>
        <FIRST_NAME>John</FIRST_NAME>
        <LAST_NAME>Doe</LAST_NAME>
    </NAME>
    <CONTACT_INFO>
        <EMAIL>john@doe.com</EMAIL>
        <PHONE>555-321-7654</PHONE>
    </CONTACT_INFO>
    <SKILLS>
        <SKILL>
          <LANGUAGE>Visual Basic</LANGUAGE>
          <EXPERIENCE>4 years</EXPERIENCE>
        </SKILL>
        <SKILL>
          <LANGUAGE>JSP</LANGUAGE>
          <EXPERIENCE>2 years</EXPERIENCE>
        </SKILL>
    </SKILLS>
 </CANDIDATE_INFO>
</CANDIDATE>

 

How do we view the XML document?

We now we have a simple standalone XML document. By standalone it means that there is no DTD associated with the document. It is a valid document as we have applied all the XML standards while creating it.

But how do we view it in a browser. It is simple to read as it is well formatted, structured and in plain text. But if we wanted to format this information in nice tables and use fonts and colors, then how would we do that?

We will look at searching through XML documents for particular data later on, but for now lets see how we can view this document in a browser window.

An XML document cannot be simply rendered by a browser unless the browser is capable of parsing the document. If you have MS IE5.0 ® then you can view the contacts file in our example as a tree type list. A tree structure is like the MS Windows Explorer where you see the main hard drive and all directories and subdirectories within in a tree leaf and node format.

Those who have a browser capable of parsing XML documents can download this file and view it locally. Once loaded, try clicking on the (+) plus and (-)minus signs and see how the resume information can be viewed as leaves and nodes.

What you see here is that your browser has used its own internal XML parser to parse the XML document and present a HTML type view for you. Microsoft IE comes with a built in XML parser and is available on your local system as msmxl.dll under your system32 directory.

But this is not that pretty and you really cannot do much with it. Except offcourse, you can look athe way it is structured and can use it as a feedback to modify some of it to better suit your needs.

 

Main |  1 |  2 |  3 |  4