XML Format for Storing Rules
Back

 

 

 

 

 


Before you begin reading this section, please understand that, as just a user, you do not have to know how the game stores rules in a file. This information is presented for those people who are interested in the details of the rules file format. If all you want to do is play the game, you need read no further.

One of the most important aspects of the game is the ability to store a set of rules separately from the game. This makes it possible for the game to support any number of bidding systems without having to change the game itself. Also, a set of rules can be sent to another person for their use and understanding. So, what does it mean to store a set of rules in a file? It means defining the format of the file in such a way that the information in the file is readily available to any person or program that knows the format.

The simplest and best way to accomplish this is to define an XML format for the file. There are other ways to define the format of a file, but, using XML provides many advantages. To understand more about XML and its advantages, please refer to the many web sites and books devoted to XML.

Part of defining an XML format includes developing either a DTD or an XML schema. A DTD or a schema is used to verify that a particular rules file adheres to the format. Unfortunately, neither have been written, yet. This is in the list of enhancements.

While reading the following chart, please refer to this short rule sample. This short sample is an excerpt from the rules distributed with the game and is displayed without being formatted so that you may view the rules as they would be saved in a file.

The first two lines in the example are the XML prolog. While a prolog is not strictly required in an XML document, it is usually advisable to include one. If a prolog is included, it must appear before the root element. That is, the prolog must come before the start of the actual rules. The first line is an XML declaration. The second line is a reference to a stylesheet.

The remainder of the file are elements constructed from the tags defined in the following chart. There are two kinds of elements in a rules file. The first kind of element, a container element, consists of a start tag, other elements, and an end tag. The second kind of element, a data element, consists of a start tag, text information, and an end tag. There are no mixed-content elements defined. That is, an element may contain either text information only or other elements only, but not both text and elements. There are no attributes defined for any of the tags.

You may notice in the above example, that container elements have their child elements indented to make the relationship clearer. This indentation is allowed, but is not required. Also, blank lines are allowed.

There are some restrictions placed upon the format of a rules file over and above the XML requirements. These restrictions are due to the game's parser. Bringing the parser up to full XML compliance is on the list of enhancements. Until then, a rules file may only contain an XML declaration and a stylesheet reference and the elements whose tags are specified below. Specifically, it can not contain processing instructions or comments. In addition, all data elements must have the start tag, data, and end tag all on the same line. Hopefully, the enhancements for the parser will be finished soon and these restrictions will be removed.

The following chart lists the container elements defined for the rules file format. Each explanation for those elements defines the data elements and container elements allowed as children of the element.

Name of tag Format of Element
rules

A rules element is the root element of a rules file. There may be only 1 rules element in a rules file.

A rules element may contain the following elements:

   type    Specifies the type of rules contained in the file. The value must be either bid or play. Only 1 type element is allowed.
   name    A name for the set of rules. Only 1 name element is allowed.
   level    The level, or version number, of the set of rules. This element is not currently used by the game, but, is defined for future use. Only 1 level element is allowed.
   owner    The name of the person who developed the set of rules. This element is not currently used by the game, but, is defined for future use. Only 1 owner element is allowed.
   contact    Contact information for the person who developed the set of rules. This element is not currently used by the game, but, is defined for future use. Only 1 contact element is allowed.
   group    Any number of group elements may be contained under the rules element.

group

This element is used to divide the set of rules into related groups.

A group element may contain the following elements:

   purpose    Describes the group's purpose. A single purpose element must be included as the first element on a rule of type group.
   if    Any number of if elements may be contained under the group element.
if

Test a player's qualities against specified values to determine the actions to take while bidding a Bridge hand.

An if element may contain the following elements:

   name    A name element names the quality to be tested. An if element must contain exactly one name element.
   comparison    A comparison element defines how the quality is to be tested. An if element must contain exactly one comparison element.
   value    A value element defines the criteria of the test. The value may be a specific string or number. Or, the value may be the name of another quality. An if element must contain exactly one value element.
   if    An if element may contain one or more if elements as children.
   set    An if element may contain one or more set elements as children.
   comment    An if element may contain one or more comment elements as children.
   bid    An if element may contain one bid element.
comment

Contains comments concerning the rules which follow it in the rule group. If a following rule sets a quality or makes a bid, the text of the comment will be available for the user's viewing.

A comment element may contain only text.

set

Sets the value of a player's quality.

A set element may contain the following elements:

   name    A name element names the quality to be set. A set element must contain exactly one name element.
   value    A value element specifies how to set the named quality. The value may be a specific string or number. Or, the value may be the name of another quality. A set element must contain exactly one value element.
bid

Describes a bid.

A bid element may contain only text.