1. LON-CAPA Logo
  2. Help
  3. Log In
 

XML and LON-CAPA

Back to Index

In LON-CAPA problems are created using an XML format. The following is a very basic problem where the user is prompted to input the answer to 2+2, where the answer is set to 4.

<problem>
<startouttext/>
What is <m>$2+2$</m>?
<endouttext/><br/>
<numericalresponse answer="4">
<textline/>
</numericalresponse>
</problem>

The basic building block of xml documents is <item></item> where item is some meaningful content. XML documents are simply a file format, so how the program that interprets your XML files defines <item>(s) will change how you use each <item>. In this case, the two items required are <problem> and <someKindOfresponse>, since problem defines where to begin and end the problem and response is required since it contains the answer(s) to said problem.

Items are placed inside one another in a hierarchical format, like folders on your hard drive. The / symbol signifies the end of the item and can be placed in one of two ways, <item/> or <item></item>. The former is used in the case where there is no content needed in the item and the latter is used otherwise. A visual representation of this in the previous code with only the XML structure would be:

<problem>
 <startouttext></startouttext>
 <m></m>
 <endouttext></endouttext/>
 <br></br>
 <numericalresponse>
  <textline></textline>
 </numericalresponse>
</problem>

Since this is a hierarchical structure, you must ensure that before ending an item, you must end all items that it contains first. Items that are added inside the <> tag that are separated from the item are variables that are defined by the specific item. For example in:

<numericalresponse answer="4">

the word answer represents the expected answer in a numerical response item, and “4” is the value that is being set for the answer. Each item (some meaningful content) has different properties that can be edited.

Also important to note is that spacing does not matter as long as there is a single space between words. For example,

<problem><startouttext />What is <m>$2+2$</m>?<endouttext /><br/><numericalresponse answer="4"><textline /></numericalresponse></problem>

will function the same as the former code. The purpose of spacing is to ensure that your documents are easily readable, both for you and those that want to use the problems you create.

    Let’s take a look at what this code does, line by line.

  1. <problem>
  2. This signifies the beginning of the document. This is required in each problem and should be the first thing included.

  3. <startouttext />
  4. Signifies that the following lines are words to be printer for the user to see.

  5. What is <m>$2+2$</m>?
  6. Prints “What is 2+2?”. <m> is a tag that signifies that you are typing math. This is useful for formatting math to look like the user expects. For example, x^2 without being placed looks like “x^2” whereas <m>$x^2$</m> will look like “x2”. The $ IS REQUIRED after <m> and before </m> for accessibility reasons.

  7. <endouttext /><br/>
  8. “Endouttext” signifies the end of text output. <br/> is an html tag that signifies that no more characters can be printed on the current line of text on your webpage.

  9. <numericalresponse answer="4">
  10. This begins the actual math problem and declares that the correct answer will be 4.

  11. <textline />
  12. This begins and ends a textline for the user to input their answer.

  13. </numericalresponse >
  14. This ends the math problem.

  15. </problem>
  16. This signifies the end of your document.

Back to Index