S
steve.cpp
Hi,
I had a question about an example in Holzner's "XML: A Beginner's
Guide." I have to learn XML quickly and picked up Holzner's book
based on some colleagues advice, as well as on some online reviews. I
have minimal experience with XML, or with JavaScript, so apologies if
this is too easy.
He has the following code posted as an example:
<html>
<head>
<title>
Retrieving data from an XML document.
</title>
<xml id="firstXML" src="hello.xml"></xml>
<script language="JavaScript">
function getData()
{
xmldoc = document.all("firstXML").XMLDocument;
nodeDoc = xmldoc.documentElement;
nodeGreeting = nodeDoc.firstChild;
outputMessage = "Greeting: " +
nodeGreeting.firstChild.nodeValue;
message.innerHTML=outputMessage;
}
</script>
</head>
<body>
<center>
<h1>
Retrieving data from an XML document.
</h1>
<div id="message"></DIV>
<p>
<input type="button" value="Read the greeting."
onclick="getData()">
</center>
</body>
</html>
When I enter this same code and load the page using Firefox on a Linux
machine, I click the "Read the greeting button, nothing appears in the
web page, when "Greeting: Hello from XML" should appear.
When I open the error console and try the button again, it indicates
that xmldoc is undefined:
xmldoc = document.all("firstXML").XMLDocument;
I don't have any JavaScript books and the local Barnes & Noble didn't
have any in stock so I did some quick searching and found that I
should use "getElementById" instead.
I tried that and had the same results:
xmldoc = document.getElementById
("firstXML").XMLDocument;
I tried a few other things but again the same result. I tried the
original code on a Windows box using IE and the code works as
described.
Is there a workaround to getting xmldoc defined correctly with Firefox?
I had a question about an example in Holzner's "XML: A Beginner's
Guide." I have to learn XML quickly and picked up Holzner's book
based on some colleagues advice, as well as on some online reviews. I
have minimal experience with XML, or with JavaScript, so apologies if
this is too easy.
He has the following code posted as an example:
<html>
<head>
<title>
Retrieving data from an XML document.
</title>
<xml id="firstXML" src="hello.xml"></xml>
<script language="JavaScript">
function getData()
{
xmldoc = document.all("firstXML").XMLDocument;
nodeDoc = xmldoc.documentElement;
nodeGreeting = nodeDoc.firstChild;
outputMessage = "Greeting: " +
nodeGreeting.firstChild.nodeValue;
message.innerHTML=outputMessage;
}
</script>
</head>
<body>
<center>
<h1>
Retrieving data from an XML document.
</h1>
<div id="message"></DIV>
<p>
<input type="button" value="Read the greeting."
onclick="getData()">
</center>
</body>
</html>
When I enter this same code and load the page using Firefox on a Linux
machine, I click the "Read the greeting button, nothing appears in the
web page, when "Greeting: Hello from XML" should appear.
When I open the error console and try the button again, it indicates
that xmldoc is undefined:
xmldoc = document.all("firstXML").XMLDocument;
I don't have any JavaScript books and the local Barnes & Noble didn't
have any in stock so I did some quick searching and found that I
should use "getElementById" instead.
I tried that and had the same results:
xmldoc = document.getElementById
("firstXML").XMLDocument;
I tried a few other things but again the same result. I tried the
original code on a Windows box using IE and the code works as
described.
Is there a workaround to getting xmldoc defined correctly with Firefox?