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

Back to Reference

xmlAttr Function

Returns the value of an XML element's attribute.

Syntax
value = xmlAttr(el, attr, defVal);
Parameters

el
XML element object which contains the attribute.
attr
The name of the attribute.
defVal
The value to return if the attribute does not exist.
Returns

Returns the value of the attribute, or defVal if the attribute does not exist.

Example 1
<CUSTOM_FOO CENTER="1">
...
</CUSTOM_FOO>
var center = xmlAttr(xmlLocData, "CENTER", 0);

The variable center will be set to "1".

Example 2
<CUSTOM_FOO>
  <FOO
    FOO="Foo Value"
  />
</CUSTOM_FOO>
xmlEl = xmlChildOf(xmlLocData, "FOO", 0);
spanFoo.innerText = xmlAttr(xmlEl, "FOO",
  "No Foo specified");
spanBar.innerText = xmlAttr(xmlEl, "BAR",
  "No Bar specified");

The HTML element spanFoo will display Foo Value, while spanBar will display No Bar specified.

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