[thelist] Is XML OT? (Long Code Sample)

Salvatore Palmisano spalmisano at usashs.com
Wed Oct 17 15:50:58 CDT 2001


Im jumping into XML with a Sams "Teach yourself XML in 24 hours" book and
have a question about a code sample.
Ive gone over this code again and again and cant find a syntax error, and
none are generated in the browser.  This is supposed to read the <XML> tag
inline data and display it in the browser in the relevant TO: BODY: , et
cetera fields.
All I get, though, is the error message for each one (Error, data not
defined).

Im using Win2k Pro SP2 and IE 6.

Anyone have an XML pointer they can share?
Thanks, and let me know if I owe a tip if this is OT.

--Salvatore


***CODE FOLLOWS***
<HTML>
<HEAD>
<TITLE>a</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function StartUp()
{
	var RootElement1=message.documentElement;
	var nodecount=RootElement1.childNodes.length;
	var loopindex;
	var CurrentNode;
	var ErrorMessage="Error, data not defined";

	if(RootElement1==null)
	{
		alert("The root node is null");
		document.write("<B><BIG>The data of the XML file cannot be
accessed</BIG></B><BR>");
	}
	else
	{

		for(loopindex=0;loopindex<nodecount;loopindex++)
		{
			CurrentNode=RootElement1.childNodes.item(loopindex);
			switch(CurrentNode. nodename)
			{
				case "TO":
				todata.innerText=CurrentNode.text;
				break;
				case "FROM":
				fromdata.innerText=CurrentNode.text;
				break;
				case "SUBJECT":
				subjectdata.innerText=CurrentNode.text;
				break;
				case "BODY":
				bodydata.innerText=CurrentNode.text;
				break;
				default:
				todata.innerText=ErrorMessage;
				fromdata.innerText=ErrorMessage;
				subjectdata.innerText=ErrorMessage;
				bodydata.innerText=ErrorMessage;
			}
		}
	}
}

//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="ffffff" onLoad="StartUp()" >
<XML ID=message>
<MESSAGE>
<TA>Student</TA>
<FROM>Author</FROM>
<SUBJECT>XML Code Islands</SUBJECT>
<BODY>This is an example of XML code embedded inside HTML code</BODY>
</MESSAGE>
</XML>
<DIV ID=to STYLE="font-weight:bold;color:blue">
TO:
<SPAN ID=todata></SPAN>
</DIV>
<DIV ID=from STYLE="font-weight:bold;color:teal">
FROM:
<SPAN ID=fromdata></SPAN>
</DIV>
<DIV ID=subject STYLE="font-weight:bold;color:red">
SUBJECT:
<SPAN ID=subjectdata></SPAN>
</DIV>
<DIV ID=body STYLE="font-weight:bold;color:magenta">
BODY:
<SPAN ID=bodydata></SPAN>
</DIV>
</BODY>
</HTML>
***CODE ENDS***
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.286 / Virus Database: 152 - Release Date: 10/9/2001





More information about the thelist mailing list