TQS Home
Trivia Quiz Shell Version 2.8 Now Available!Bot Productions Home
TQS 2.5

Back to Reference

xmlRetrieveEx Function

Gets the XML data from a specified element or attribute.

value = xmlRetrieveEx(elStart, elPath, attr,
  defVal, retrNum);

The XML element to start at when finding the appropriate data. The following values have special meaning:
Start at the root element of the document (the TQS element).
Start at the current location's type-specific data element (the CUSTOM_* element).
Start at the current location's element (the LOC element).
The path to the element or attribute to be retrieved. This is in the form of childEl[x]/childEl[y]/.../childEl[z]. Each childEl is an element tag name; the number in brackets specifies the zero-based index of each element to use.
The name of the attribute of the last element of the path. To specify that the contents of the element should be returned, pass "".
The default value to return if one of the elements in the path, or the attribute, does not exist.
If equal to 1, the function will return the number of elements at the end of the path with the specified element tag name.

Returns either the number of elements, the contents of an element, or an attribute value, based on the parameters.


The xmlRetrieve function performs the same operations, but with less flexibility.

Example 1
    <BAR>Inside Global Bar</BAR>
spanFoo.innerText = xmlRetrieveEx(null,
  "GLOBAL[0]/CUSTOM_FOO[0]/FOO[0]", "",
  "Default Global Foo", 0);
spanBar.innerText = xmlRetrieveEx(null,
  "GLOBAL[0]/CUSTOM_FOO[0]/BAR[0]", "",
  "Default Global Bar", 0);

The HTML element spanFoo will display Default Global Foo, while spanBar will display Inside Global Bar.

Example 2
    <BAR COLOR="#00FF00"/>
spanFoo.style.color = xmlRetrieveEx(null,
  "#000000", 0);
spanBar.style.color = xmlRetrieveEx(null,
  "#FFFFFF", 0, 0);

The HTML element spanFoo will have the color #FF00FF, while spanBar will have the color #00FF00.

Example 3
      <BAR VALUE="Bar 1"/>
      <BAR VALUE="Bar 3"/>
spanHead.innerText = xmlRetrieveEx(xmlCurLoc,
  "HEADING[0]", "", "No Heading", 0);
val = xmlRetrieveEx(xmlLocData,
  "BARS[0]/BAR[0]", "VALUE", "Default", 0);
val += "... ";
val += xmlRetrieveEx(xmlLocData,
  "BARS[0]/BAR[1]", "VALUE", "Default", 0);
val += "... ";
val += xmlRetrieveEx(xmlLocData,
  "BARS[0]/BAR[2]", "VALUE", "Default", 0);
val += "... ";
spanBar.innerText = val;
spanHead.innerText = xmlRetrieveEx(xmlCurLoc,
  "HEADING[0]", "", "No Heading", 0);
numBars = xmlRetrieveEx(xmlLocData,
  "CUSTOM_FOO[0]/BAR", "", 0, 1);
val = "";
for(i = 0; i &lt; numBars; i++)
  val += xmlRetrieveEx(xmlLocData,
    "BARS[0]/BAR["+i+"]", "VALUE",
	 "Default", 0);
  val += "... ";
spanBar.innerText = val;

The HTML element spanHead will contain Foo; the element spanBar will display Bar 1... Default... Bar 3... . Both script fragments achieve the same result.

©2016 Bot Productions. All rights reserved.Last Updated: September 9, 2007