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

Back to Reference

xmlRetrieve Function

Gets data from a specified path of elements, starting at the root.

Syntax
value = xmlRetrieve(elPath, defVal, index, retrNum);
Parameters

elPath
The path to the element or attribute to be retrieved. This is in the form of childEl/childEl/.../childEl:attr. Each childEl is an element tag name; the :attr portion, optional, specifies the name of the attribute of the last childEl that should be returned.
defVal
The default value to return if one of the elements in the path, or the attribute, does not exist.
index
If the more than one element at the end of the path exists with the same name, this specifies the zero-based index of which element to use.
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

An attribute can only be specified at the end of a path.

The xmlRetrieveEx function performs the same operations, but with more flexibility.

Example 1
<GLOBAL>
  <CUSTOM_FOO>
    <BAR>Inside Global Bar</BAR>
  </CUSTOM_FOO>
</GLOBAL>
spanFoo.innerText = xmlRetrieve(
  "GLOBAL/CUSTOM_FOO/FOO", "Default Global Foo",
  0, 0);
spanBar.innerText = xmlRetrieve(
  "GLOBAL/CUSTOM_FOO/BAR", "Default Global Bar",
  0, 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 = xmlRetrieve(
  "GLOBAL/CUSTOM_FOO:COLOR", "#000000", 0, 0);
spanBar.style.color = xmlRetrieve(
  "GLOBAL/CUSTOM_FOO/BAR:COLOR", "#FFFFFF", 0, 0);

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

Example 3
<GLOBAL>
  <CUSTOM_FOO>
    <BAR VALUE="Bar 1"/>
    <BAR/>
    <BAR VALUE="Bar 3"/>
  </CUSTOM_FOO>
</GLOBAL>
val = xmlRetrieve("GLOBAL/CUSTOM_FOO/BAR:VALUE",
  "Default", 0, 0);
spanBar.insertAdjacentText("beforeEnd",
  val + "... ");
val = xmlRetrieve("GLOBAL/CUSTOM_FOO/BAR:VALUE",
  "Default", 1, 0);
spanBar.insertAdjacentText("beforeEnd",
  val + "... ");
val = xmlRetrieve("GLOBAL/CUSTOM_FOO/BAR:VALUE",
  "Default", 2, 0);
spanBar.insertAdjacentText("beforeEnd",
  val + "... ");
numBars = xmlRetrieve("GLOBAL/CUSTOM_FOO/BAR",
  "", 0, 1);
for(i = 0; i &lt; numBars; i++)
{
  val = xmlRetrieve(
    "GLOBAL/CUSTOM_FOO/BAR:VALUE", "Default",
    i, 0);
  spanBar.insertAdjacentText("beforeEnd",
    val + "... ");
}

The HTML 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