Build an XML file

Look at an XML file

Click the link to see a very simple XML file. In your browser, select   -view -page source   to see the source code I typed. Close the source code window. Use the back arrow from the sample page, to return to this page.

The first line in the source code is <?xml version="1.0" encoding="UTF-8"?>
This is an XML declaration, that says this is an XML document.

The <name> tag is at the top; it starts the page.
The </name> tag is at the bottom.
All the other XML elements are contained within this <name>   </name> container.
XML tags are in pairs. A container, and all its contents, is called an element in XML.
All elements are contained in the one root element. In this case, the root element is name.

Within the name element, we find the first element, followed by the middle element, followed by the last element.

The other typing is just text. There is text within the first element, the middle element, and the last element.

So we see that:

  • There is ONE root element, which contains all the other elements.
  • All other elements are contained within another element.
  • This makes a hierarchy of elements, from the root down.

Create a directory for your web pages

You need a directory to keep your web pages in while you work on them, before you put them up on the Internet. The links at the left lead to pages which tell you how to setup at home, and how to set up a windows account at school. You can work at home ( or other place where you have a computer ) or you can work at school. Many students work both at home and at school.

You can carry work between home and your windows account at school using a USB flash drive. At the end of the quarter, you may wish to carry a copy of all of your work from school to home, because the student accounts are destroyed at the end of the quarter.

Get an editor

You can use a simple text editor, such as Microsoft notepad. Be sure to use   Save as   with the file extension xml with notepad. You can use a simple text editor, because we are just typing text. On the other hand, it is better to use an editor that is built to support XML. They have additional features, that we will use.

Do NOT use a word processor, such as Microsoft WordPad or Microsoft Word. They will put stuff into your simple text that you do not want.

The book Beginning XML suggests you download and use the Codeplot editor and development environment. I tried it, but I found their website was sometimes down for extended periods of time.

I tried the Cooktop XML editor and development environment. It seems nice and simple. However, it is no longer supported.

I tried the XML Copy Editor. It is simple to use. It does almost everything I want it to do. I will use this one.

If you find a better XML editor, please let me know.

The links at the left take you to the download sites for these editors. You may download one at home, and use it.

If you use a simple editor, such as notepad, you can check to make sure that your XML is well formed by looking at it with Firefox. Firefox, like all programs that look at XML, is required to check to make sure the XML is well formed.
Later, we will build a Document Type Definition for our web pages. Browsers, and some other programs, do not validate the web page against the Document Type Definition. We will deal with the problem later.

If you use an XML editor, it can check to make sure your XML is well formed and valid. The following is a list of some things you can do with Cooktop. Other XML editors will be similar.

  • Start the Cooktop program
  • Click the blank white small page near the top left, to open a new document.
  • Type a little XML. Do not type too much at once.
  • In the menu select -Tools -Format Current XML - Tidy. This will make your page look good.
  • In the menu select -XML -Validate. This will check to make sure our XML is well formed. It does not actually validate the page yet, because we do not yet have a Document Type Definition. (This will automatically save our document. You may wish to backup a document before you start to change it.)
  • Type more XML, tidy, and validate.
  • If it shows error messages, fix them.

Build an XML file

Now you are ready to build your own xml file. Carefully note the following things:

  • Case is important. <Hello> is not the same as <HELLO>
    It makes a difference if you type in lower case small letters or in upper case capital letters.
  • The contents of a container is indented two or three spaces. If you do not indent, it is hard to find the closing tag that matches the opening tag of the container.

Look at the sample page. Type your own page. Make your page like the sample, except use your name, rather than Johann Sebastian Bach.

Save your page in your public_html directory. When you save a web page in the notepad editor you must specify - save as - all files. If you do not, notepad will add .txt at the end of the file name. The .txt will be hidden by Windows so you do not see it. The .txt at the end will keep your file from working as an XML file. Save it with the name lab1.xml .

Get a good browser

You need a good browser. Mozilla Firefox is very good. I usually use Firefox. Opera is also very good. Safari has a good reputation in the Macintosh environment. Pick one, download it, and install it.