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.

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

elStart
The XML element to start at when finding the appropriate data. The following values have special meaning:
null
Start at the root element of the document (the TQS element).
xmlLocData
Start at the current location's type-specific data element (the CUSTOM_* element).
xmlCurLoc
Start at the current location's element (the LOC element).
elPath
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.
attr
The name of the attribute of the last element of the path. To specify that the contents of the element should be returned, pass "".
defVal
The default value to return if one of the elements in the path, or the attribute, does not exist.
retrNum
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

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

Remarks

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

Example 1
<GLOBAL>
  <CUSTOM_FOO>
    <BAR>Inside Global Bar</BAR>
  </CUSTOM_FOO>
</GLOBAL>
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
<GLOBAL>
  <CUSTOM_FOO COLOR="#FF00FF">
    <BAR COLOR="#00FF00"/>
  </CUSTOM_FOO>
</GLOBAL>
spanFoo.style.color = xmlRetrieveEx(null,
  "GLOBAL[0]/CUSTOM_FOO[0]", "COLOR",
  "#000000", 0);
spanBar.style.color = xmlRetrieveEx(null,
  "GLOBAL[0]/CUSTOM_FOO[0]/BAR[0]", "COLOR",
  "#FFFFFF", 0, 0);

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

Example 3
<LOC ID="3" TYPE="CUSTOM_FOO">
  <HEADING>Foo</HEADING>
  <CUSTOM_FOO>
    <BARS>
      <BAR VALUE="Bar 1"/>
      <BAR/>
      <BAR VALUE="Bar 3"/>
    </BARS>
  </CUSTOM_FOO>
</LOC>
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.

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