Introduction to writing XML

Introduction

XML is a metalanguage written in SGML that is used to allow for the easy interchange of documents on the World Wide Web. Basically, we use it to define scene annotations and actions.

Enough talk, lets write some! Here is a blank.xml file to get you started. Be sure to save this in Annot3D/xmlFiles/ so that it can find the .dtd file. Open it in WordPad or NotePad to edit it.

Declare the DOCTYPE

The xml needs to know what .dtd file to look for. Don't worry about what a .dtd is, just add the middle line to make the file look like this:
- For a scene (adding data or annotations)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE scene SYSTEM "scene.dtd">
<?cocoon-process type="xslt"?>


- For a userEvent (mouse events)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE userEvent SYSTEM "userEvent.dtd">
<?cocoon-process type="xslt"?>

Add a Tag

XML uses "tags" to classify and declare things. Tags are placed before and after the specification you want to make.
- A beginning tag is a word type surrounded by <>'s, such as <green>.
- Next comes the body (i.e. specification you want to make), such as 1 .
- Now the ending tag is the same word in the beginning tag only this time you use a backslash before the word, such as </green>.
A complete tag looks like this:
<green>1</green>.

It doesn't matter if there are spaces or returns inside the tag. You could also do it this way:
<green>
__1
</green>
.
It helps to indent the body of a tag when it is on a separate line.

Tag Properties

Some tags have special properties associated with them. These are easy enough to use.
- Just after the beginning tag word, (<scene ) type the property name and an = , like this clientID= .
- Now type the value you want the property to have in quotes and close off the tag with a > , like this: "one">
- The body and ending tag are the same as before: scenevalue</scene>
You can have more than one property per tag. Order doesn't matter! Just put them all after the word in the beginning tag. Separate the properties with a space.
<scene name="test" author="" clientID="one">scenevalue</scene>

Nested Tags

Sometimes, you can place tags inside of tags. Thus, a tag or multiple tags can be the body of another tag.
You can type it all on one line like this:
<scene><green>1</green></scene>
Or on multiple lines for easy comprehension:
<scene clientID= "one">
__ <green>1</green>
__ <blue>.5</blue>
</scene>

Example XML File

Now you're a pro! Here's an example.xml file of completed XML. Can you identify the tags? For more example fun, right click on this page an choose "View Source". This shows the xml that codes this web page. You can do this on any web page.

A good thing about XML is that you can have multiple occurances of the same tag. The possibilities are endless so go ahead and put your XML knowledge to use!



Last modified: Tue Dec 16 21:50:13 MDT 2003 by Janna Balling