An XML Sample

In the Math Game program, I create an XML language that describes an elementary math test. The following XML code describes a test for the Math Game program. The code is only a portion of the document, but the omitted portion is repetitive.

or the purchase of special licenses, is intriguin y

<?xml version="1.0" encoding="UTF-8"> <test>

<problem>

<number>1</number> <left_operand>2</left_operand> <operator>+</operator> <right_operand>1</right_operand> <answer>3</answer> </problem> <problem>

<number>2</number> <left_operand>3</left_operand> <operator>+</operator> <right_operand>2</right_operand> <answer>5</answer> </problem> </test>

You should be able to recognize that this defines the structure of an elementary math test. The first line of the code is an XML declaration and defines the XML version and character encoding used in the document. In this example, the document conforms to the 1.0 specification of XML (see http://www.w3c.org) and uses the Unicode text formatting character set (UTF-8).

<?xml version="1.0" encoding="UTF-8">

Most XML files begin with a similar line and Excel requires this line, or it won't recognize the file as XML and will try to open it as an ordinary text file.

I invented all other tags (<test>, <problem>, <number>, <left_operand>, <operator>, <right_operand>, and <answer>) used in the document, and examination of the XML document's structure shows a repetitive pattern. The document consists of a set of two <problem> </problem> tags nested within the root tag <test> </test>. There are also several tags describing the problem number, operands, operator, and answer nested within each <problem> </problem> tag; thus, there is a hierarchy to the document's structure that follows from <test> to <problem> to all remaining elements.

A test with only two problems doesn't really test a student's ability. In reality, the XML documentld contain several more <problem> tags, but I've left them out for brevity

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment