Introduction to XML

| HOME | SYLLABUS | CALENDAR AND EXERCISES |

Introducing XML

Remember to save all work you do. We will keep on processing the same files in later exercises.

You can edit XML files with any text editor like Notepad, or with program or HTML editors which understand XML like Notepad++ or Eclipse. There are also editors developed specifically for XML editing, and in later exercises you could use MS Studio.NET or Expression.

Practice 1a: XML tree structures 

Analyse the XML file below. Draw a tree diagram of its structure using Visio or Jude.

<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<publication>
<newsitem>
<source>
<agency>STT</agency>
<editor>Miller</editor>
</source>
<class>local</class>
<article>
<heading>Snowstorms in Lapland</heading>
<text>snow.html</text>
<summary>snowx.html</summary>
</article>
</newsitem>
</publication>

Create the file for example with Notepad++ and save as pract1a.xml. Open the file with Internet Explorer. Compare the display with Firefox.

Practice 1b: XML structure

Analyse the following XML file. Draw a tree diagram and correct the errors in design.

<?xml version='1.0' standalone='yes'?>
<phonebook>
<company>
<cname>Konera</cname>
<exchange>09-999000</exchange>
</company>
<president>Paul Proteus
<extension>09-9990011</president></extension>
<secretary>Katharine Finch <extension>09-9990012</secretary></extension>
<company>
<cname>Kordea</cname>
<exchange>09-888000</exchange>
</company>
<president>Ed Finnerty
<extension>09-8880011</president></extension>
<secretary>Bud Calhoun
<extension>09-8880012</secretary></extension>
</phonebook>

Save your file as prac1b.xml. Try also how browsers react to the XML declaration with different character encodings (assuming that your editor is able to save in these encodings):

<?xml version='1.0' encoding='UTF-16' standalone='yes'?>
This is the same as Unicode
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>

Practice 1c: XML file, CD information

Plan an XML description for a music CD. You could use a root element called <CDcatalog>. Information about the contents should include at least name of the record, artists, songs, publishing year, and music category/ genre. You can add more information e.g. about each track (number, duration, name, etc.) Plan first the tree structure of your XML data, and then find some real data from the Web. Save as pract1c.xml and test with browsers.

Next, add some information as attributes to the cd element, for example as below

<CD serial='B6B41B' disc-length='36:55'>

Save as pract1c2.xml and test. Fix errors. Add the following comment:

<!-- This CD has more tracks than in this file -->

Practice 1d: Curriculum information  

Create an XML file that contains the information on your current courses. Try to plan it in a way that it could be extended to contain the study plan and possibly an entire curriculum. Make a document instance with contents.

| HOME | SYLLABUS | CALENDAR AND EXERCISES |

Created by: Jaana Holvikivi
Updated: 10.1.2012