The XML File Format

XML is the eXtensible Markup Language. It is very similar to HTML. In fact it was created as a generalization of HTML that is simpler than SGML. Microsoft provides a nice discussion of XML. XML files are created using tags just as in HTML. Each tag has a type, zero or more attributes and zero or more children. Each child is either a block of text or another tag.  Tags can appear with or without children. A tag without children (attributes only) ends with a "/" before the closing ">". For example:

        <ghost size="huge" transparency="0.5" />
In this example, the type of the tag is "ghost". It has two attributes "size" and "transparency". All attributes have string values that are enclosed in double quotes. Please note that the attributes of a tag can be given in any order. The "/>" at the end of the tag indicates that there are no children for this tag.

Some tags have children. If a tag has children it is terminated by ">", without the "/". After all of the children there must be a corresponding closing tag "</type>". For example:

         <flock>
                <goose size="little" color="white" name="Ted"/>
                <goose size="medium" name="Mother Goose" color="gray">
                        Many things have been written about Mother Goose.
                        What is not mentioned is that she had children.
                        <goose size="little" name="Spud"/>
                        <goose size="tiny" name="Spec"/>
                </goose>
                <goose size="huge" color="black" name="Buck"/>
        </flock>
In this example the <flock> tag has no attributes but has three child tags which are of type <goose>. Note
that the goose named "Mother Goose" has three children. The first is a text block that mentions several things about Mother Goose. The second and third are other <goose> tags. Because Mother Goose has children her tag is not terminated with a "/>". Instead a </goose> tag appears after all of the children.

XML defines a tree of objects which have types, attributes (all with string values) and children.

It is possible that you may find C++ code for XML parsers on the Internet. You may not use such code, you must write your own.
 

Chess Games in XML Format

For the purpose of this project, we will define a specialized XML format for encoding a game of chess. This format does not conform to any known standard for either XML or chess. Our format defines the following XML tags, which will be described later. Each of these XML tags are described in more detail below:

<board>

The board tag is used to describe the current state of the chess board. It has no attributes but has <piece> tags as its children.

<piece>

A <piece> tag defines all the information about a chess piece that is still on the board. The <piece> tag has the following attributes. An example of a <board> tag with <piece> tags is shown below:
 

<history>

The <history> tag is to store the history of moves in the game. The <history> tag has no attributes. It can only have <move> tags as children. The <move> tags should appear inside the <history> tag in chronological order, the first <move> tag representing the first move in the game.

<move>

A <move> tag is used to represent a move that has been made during the course of the game. The move tag has no attribute but may have up to three <piece> tags as children. The first piece tag shows the original position of the piece that was moved. The second piece tag shows the final position of the piece after it was moved. The third piece tag is optional. It represents a piece that was taken when the piece was moved. The only time that the type of a piece can be different for the first and second piece tags within a move tag is if the piece is a pawn that had reached the other side of the board and changed into another piece. An example of a <history> tag with <move> tags is shown below:
  When a pawn changes to another piece, this should be represented by changing the piece type in the move that takes the pawn into the final row of the board. For example:

Example File

Here is an example of a short chess game in XML format.