ICT336 title
Murdoch University logo

Laboratory Week 6 - XML Document


Learning Objectives:

  1. Learn how to create well-formed and valid XML documents.
  2. Learn how to verify that an XML document is well-formed and valid.
  3. Understand how web servers and a web clients deal with XML documents.

Required Reading:

Lectures: Week 5 lectures
Sybex Textbook XML Complete Chapters 1-4, 6.

Access to Software:

The following exercises requires a browser on your local machine, as well as ssh access to gryphon.murdoch.edu.au.

Access to required files:

The following exercises make use of XML files and Perl scripts available in the unit coordinator's directory (~hiew/examples/xml/) on gryphon. Use the command "cp" to copy the file over to your work directory on gryphon. Eg.

gryphon:~> mkdir ~/labwk6
gryphon:~> cp ~hiew/examples/xml/* ~/labwk6

Instructions:

  1. Use a text editor to open the file course-notwf.xml. It is an XML document that is not well-formed. It contains one simple mistake. Can you spot the mistake? Regardless of whether you can spot the mistake or not, DO NOT correct the mistake for now.
  2. Use the script checkwf.pl to check if the XML document is well-formed. Type the command:

    gryphon:~/labwk4> perl checkwf.pl course-notwf.xml
    syntax error at line 3, column 0, ...


    This indicates that the script has detected a syntax error at column 0 line 3 of course-notwf.xml. Is that the same mistake as you picked in (1) above?

    Correct the mistake in course-notwf.xml by deleting the problem text. Save the corrected file as course-wf.xml. Try checking the document again with checkwf.pl to confirm you have made the right correction.

    You may use a text editor to view the source code for checkwf.pl, but your are not required to understand the code for now. We will deal with writing XML parsers in future lectures and labs.
  3. Now try the XML document course-invaliddtd.xml containing a DTD. This document also contains a mistake. Repeat the same steps in (1) and (2) with this document, except use the script checkvaliddtd.pl instead of checkwf.pl. Save the corrected XML file as course-validdtd.xml.
  4. (For students with Micorsoft Internet Explorer 5+) Start up IE5+ and load course-valid.xml using File>Open. IE5 has an in-built XML parser. Once it has parsed the document, it displays it in a tree-structure, and also add some interactivity (eg. try clicking on the + and - symbols). Use View>Source menu item to look at the source of what it is displaying - it is exactly the content of the XML file.

    Use IE5 to load course-notwf.xml. You should see that it detects the error and displays where it believes the error is.

    IE5 has a parser called MSXML, which is a non-validating parser (ie. it does not validate the elements against the given DTD). Use IE5 to load course-notvaliddtd.xml. You should see that it does not detect the validity error.
  5. Try using the browsers you have available on your local machines to load the XML document. Most browsers that do have in-built XML parsers (eg Netscape 6+) will not display the content in fancy ways like IE5. Some that do not have any in-built support for XML will only display it as a normal text file, with the tags appearing as well. You will learn in future labs how to prepare the XML file so that the display is more appropriate.
  6. Now that we have seen how your browsers can deal with XML files, let's try getting web servers to serve XML files. First, try it with your Apache web server. Use seccure FTP to upload course-validdtd.xml to your Apache's htdocs directory. Start your server using apachectl, and use different web clients to access the file from your server:
    1. Use getall.pl from week 4's lab to confirm that the "Content-type" header field contains the value "text/xml".
    2. Use your own browsers to request the same URL as (i). You should see the same display as in (4) and (5).

  7. Stop your Apache server. Copy course-validdtd.xml to the same directory as your web_serial.pl and Web.pm, and start your web_serial.pl with your port number. Now do the same as (7). Note the following:
    1. When using getall.pl, have a look at the "Content-type" header field. It should be "text/plain". This is because the default type set the lookup_file() subroutine in Web.pm is "text/plain".
    2. When using any browser besides IE5 to request the URL, you should see the file content displayed as plain text. This is because it received "text/plain" as the MIME-type for this file.
    3. When using IE5 to request the same URL, the file gets displayed in the same interactive tree format as in (4). This is in spite of the "Content-type" header stating that the file is "text/plain". In this case, IE5 have determined on its own that the file is really an XML file, and therefore parses it and displays it as it sees fit. Such is the philosophy of Microsoft.
  8. Besides using the perls scripts above and using your browsers, there are also other software which can be used to verify the well-formedness and validity of XML documents. Some of them are web based. Eg.
    In these services, you have a choice of uploading your local XML file, cutting-and-pasting the XML to a form, or specifying a URL where your XML file is. Use any of these methods to try these services on course-notwf.xml and course-notvaliddtd.xml. You may find the error messages more useful than the perl scripts supplied.

Exercises:

  1. Using a text editor, add all of the following information on a unit into course-validdtd.xml file. You must determine the appropriate elements to put them into. Modify the DTD if you have to.

    Unit name: ICT333 IT Project
    Lecturer's name: Arnold Depickere
    Semester: 1

  2. Put the DTD section of the course-validdtd.xml into a file called course.dtd. Modify course-validdtd.xml so that it refers to this external DTD instead of using an internal DTD.

  3. Look at the source code in mistakes.xml. This document contains multiple mistakes according to the rules of well-formedness and validity. Try and find them manually without using the software above. Correct the mistakes, and then verify that you have found them all using the software described above.

    You do not need to understand the content or the meaning of any of the tags in the document. The point of your exercises now is to determine how well you can deal with structure alone.

    When making your corrections, make as few modifications as you can. Obviously, deleting the whole DTD and leaving only one empty root element will 'correct' all mistakes, but that defeats the aim of getting you to practice XML syntax.

  4. Add to your course-validdtd.xml document.some of the extra information available on ICT336 official front page http://online.murdoch.edu.au/public/ICT336/.
  5. Look at the University Handbook entry for BSc in Internet Computing at Murdoch University. Think about how all the relevant information may be added to the course-validdtd.xml document (since it will be a very cumbersome process, you do not need to actually do it).

Assessable Tasks:

Exercises 1, 2 and 3.

Internal students should demonstrate to your tutor by executing your scripts with your tutor present. This must be done in week 6, 7 or 8. No marks will be awarded if the work is demonstrated after that - your tutor have no discretionary power on this deadline.

External students should submit the scripts and sample runs during the deadline as indicated in the Study Schedule.

H.L. Hiew
Unit Coordinator


Document author: H.L. Hiew, Unit Coordinator
Last Modified: Wednesday, 12-May-2004 16:55:59 MST
Disclaimer & Copyright Notice © 2004 Murdoch University
This document is relevant for semester 1, 2004 only