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

Back to Reference

xmlChildOf Function

Returns a specific child XML element of another XML element.

Syntax
xmlEl = xmlChildOf(el, tagName, index);
Parameters

el
XML parent object.
tagName
The element tag name.
index
Zero-based index of which element to return, if multiple elements have the same tag name.
Returns

Returns the specified XML element, or a null reference if it does not exist.

Example 1
<CUSTOM_FOO>
  <FOO>
    <BAR>Inside Bar</BAR>
  </FOO>
</CUSTOM_FOO>
fooEl = xmlChildOf(xmlLocData, "FOO", 0);
barEl = xmlChildOf(fooEl, "BAR", 0);
spanBar.innerText = barEl.text;

The HTML element spanBar will display Inside Bar.

Example 2
<CUSTOM_FOO>
  <FOO>Inside Foo 1</FOO>
  <FOO>Inside Foo 2</FOO>
  <FOO>Inside Foo 3</FOO>
</CUSTOM_FOO>
foo = xmlChildOf(xmlLocData, "FOO", 0);
spanFoo.insertAdjacentText("beforeEnd",
  foo.text + "... ");
foo = xmlChildOf(xmlLocData, "FOO", 1);
spanFoo.insertAdjacentText("beforeEnd",
  foo.text + "... ");
foo = xmlChildOf(xmlLocData, "FOO", 2);
spanFoo.insertAdjacentText("beforeEnd",
  foo.text + "... ");
for(i = 0;
  i &lt; xmlNumChildOf(xmlLocData, "FOO");
  i++)
{
  foo = xmlChildOf(xmlLocData, "FOO", i);
  spanFoo.insertAdjacentText("beforeEnd",
    foo.text + "... ");
}

The HTML element spanFoo will contain the following:
Inside Foo 1... Inside Foo 2... Inside Foo 3...

Both script fragments achieve the same result.

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