getElementById Method
Returns the Node object that has an id attribute with the specified value.

Syntax
var oNode = Document.getElementById(sElementID);

Parameters
sElementID Required. the id of the desired node.

Return Value
The Node object with the specified id.

Remarks
The getElementById method retrieves nodes more quickly than other DOM methods because references to nodes with id attributes are stored in a hash table.
While other XML parsers allow the developer to designate any aribitrary attribute name to be of type id through a document type definition (DTD), the Tellme platform has predefined the attribute name "id" or "ID" to designate an id. The id attribute was selected so that developers need not define a DTD and so that the Tellme platform need not slow down the parsing process by first parsing a DTD.
Values of the id attribute must begin with a letter or an underscore.
The values of the id attribute should be unique across all elements in the XML document. If a value is encountered more than once in an XML document, only the first node encountered will be returned when that id is requested by a call to the getElementById method.
If an element with the specified id does not exist, the getElementById method returns null.
Examples

The example below utilizes the following sample data describing a stock quote. The Tellme platform does not use a DTD to validate the data referenced by the data element, but the DTD has been included in the sample data to better describe the schema. Do not include the DTD in the data returned to the data since the DTD constitutes a substantial amount of data that will not only need to be retrieved and parsed if it is in-line.

<?xml version="1.0"?>
<!DOCTYPE quote [

<!ELEMENT quote (name, ticker, open, last, change, day_high, day_low)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ticker (#PCDATA)>
<!ELEMENT open (#PCDATA)>
<!ELEMENT last (#PCDATA)>
<!ELEMENT change (#PCDATA)>
<!ELEMENT day_high (#PCDATA)>
<!ELEMENT day_low (#PCDATA)>

<!ATTLIST name
	id ID #REQUIRED>
<!ATTLIST ticker 
	id ID #REQUIRED>
<!ATTLIST open 
	id ID #REQUIRED>
<!ATTLIST last 
	id ID #REQUIRED>
<!ATTLIST change 
	id ID #REQUIRED>
<!ATTLIST day_high 
	id ID #REQUIRED>
<!ATTLIST day_low 
	id ID #REQUIRED>

]>

<?access-control allow="*"?>
<quote>
   <name id="qname">Ford Motor Company</name>
   <ticker id="qticker">F</ticker>
   <open id="qopen">28.35</open>
   <last id="qlast">28.72</last>
   <change id="qchange">.54</change>
   <day_high id="qday_high">29.03</day_high>
   <day_low id="qday_low">28.03</day_low>
</quote>

The following example retrieves the name and price of the stock using the getElementById method.

<vxml version="2.0">
<data src="quote2.exml" name="oQuote"/>

<form id="get_quote">
   <script><![CDATA[
      // retrieve the company name
      var sCoName = oQuote.getElementById("qname").firstChild.data;
      // retrieve the price per share
      var sPrice = oQuote.getElementById("qlast").firstChild.data;
   ]]></script>
   <block>
      <audio><value expr="sCoName"/> is currently at <value expr="sPrice"/> per share.</audio>
   </block>
</form>

</vxml>


Applies To
Document
[24]7 Inc.| Terms of Service| Privacy Policy| General Disclaimers