Hello good folks,
I just bought Inside XML, kind of on Ajith's "kind-of" recommendation, to help me prepare for IBM's XML certification (see
http://www.javaranch.com/ubb/Forum31/HTML/000367.html ). Well the first programming assignment, a 15 minute IE 5+ javascript loading and reading of a simple XML document, is returning a null object instead of the root element.
This is the HTML & Jscript:
<HTML>
<HEAD>
<TITLE>
Reading XML element values
</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function readXMLDocument()
{
var xmldoc, meetingsNode, meetingNode, peopleNode
var first_nameNode, last_nameNode, outputText
xmldoc = new ActiveXObject("Microsoft.XMLDOM")
xmldoc.load("meetings.xml")
meetingsNode = xmldoc.documentElement
meetingNode = meetingsNode.firstChild
peopleNode = meetingNode.lastChild
personNode = peopleNode.lastChild
first_nameNode = personNode.firstChild
last_nameNode = first_nameNode.nextSibling
outputText = "Third name: " +
first_nameNode.firstChild.nodeValue + ' '
+ last_nameNode.firstChild.nodeValue
messageDIV.innerHTML=outputText
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<H1>
Reading XML element values
</H1>
<INPUT TYPE="BUTTON" VALUE="Get the name of the third person"
ONCLICK="readXMLDocument()">
<P>
<DIV ID="messageDIV"></DIV>
</CENTER>
</BODY>
</HTML>
and "meetings.xml" is as follows:
<?xml version="1.0"?>
<MEETINGS>
<MEETING TYPE="informal">
<MEETING_TITLE>XML In The Real World</MEETING_TITLE>
<MEETING_NUMBER>2079</MEETING_NUMBER>
<SUBJECT>XML</SUBJECT>
<DATE>6/1/2002</DATE>
<PEOPLE>
<PERSON ATTENDENCE="present">
<FIRST_NAME>Edward</FIRST_NAME>
<LAST_NAME>Samson</LAST_NAME>
</PERSON>
<PERSON ATTENDENCE="absent">
<FIRST_NAME>Ernestine</FIRST_NAME>
<LAST_NAME>Johnson</LAST_NAME>
</PERSON>
<PERSON ATTENDENCE="present">
<FIRST_NAME>Betty</FIRST_NAME>
<LAST_NAME>Richardson</LAST_NAME>
</PERSON>
</PEOPLE>
</MEETING>
</MEETINGS>
On the first document "meetings.xml" is in the same directory but "meetingsNode = xmldoc.documentElement" assigns meetingsNode to null and the following line thus creates an error. My best guess is that either the book has an error not mentioned in the errata or I am missing something fundamental and assumed.
Does anyone have any insights?
Meadowlark Bradsher