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
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.
<board> <piece type="rook" color="white" column="0" row="7"/> <piece type="knight" color="white" column="1" row="7"/> <piece type="bishop" color="white" column="2" row="7"/> <piece type="queen" color="white" column="3" row="7"/> <piece type="king" color="white" column="4" row="7"/> <piece type="bishop" color="white" column="5" row="7"/> <piece type="knight" color="white" column="6" row="7"/> <piece type="rook" color="white" column="7" row="7"/> <piece type="pawn" color="white" column="3" row="6"/> <piece type="pawn" color="white" column="4" row="6"/> </board>
<history> <move> <piece type="pawn" color="white" column="3" row="6"/> <piece type="pawn" color="white" column="3" row="5"/> </move> <move> <piece type="pawn" color="black" column="7" row="1"/> <piece type="pawn" color="black" column="7" row="2"/> </move> <move> <piece type="bishop" color="white" column="2" row="7"/> <piece type="bishop" color="white" column="7" row="2"/> <piece type="pawn" color="black" column="7" row="2"/> </move> </history>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:
<move> <piece type="pawn" color="white" column="3" row="1"/> <piece type="queen" color="white" column="3" row="0"/> </move>
Example File
Here is an example of a short chess game in XML format.