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?
It's a proprietary thing by Microsoft.
The XML spec reads (<http://www.w3.org/TR/REC-xml/#sec-common-syn>):
> Names beginning with the string "xml", or with any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification.
So an element type xml (<xml id="firstXML" src="hello.xml"></xml>) is
not allowed in XML-based languages. The code quoted by the OP, however,
looks like some HTMLish tag soup. But, well...
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
> <html>
> <head>
> <title>
> Retrieving data from an XML document.
> </title>
> <xml id="firstXML" src="hello.xml"></xml>
> 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?
There is no element named 'xml' in HTML 4 or XHTML 1. Only IE/Windows
supports such an element for so called XML data islands.
With other browsers if you want to use XML data you can use JavaScript
and XMLHttpRequest to load the data. Since IE 7 IE also supports that,
with earlier versions you can use an ActiveXObject.
https://developer.mozilla.org/En/Using_XMLHttpRequest
That way you can request application/xml or text/xml content and the
XMLHttpRequest object loads and parses that and exposes a responseXML
property with an XML DOM document.
--
Martin Honnen
http://msmvps.com/blogs/martin_honnen/
HTML is not an XML-based language (at least not until you get to XHTML).
But if you're using something proprietary, I can't help.
Any book that gives this as an "example" of HTML should probably be set
aside. It's neither HTML nor XHTML, and it shows signs of having been
constructed by someone unfamiliar with the conventions of markup. The
fact that it might work in IE and nowhere else is likely to be
sufficient reason to discard it.
///Peter
--
XML FAQ: http://xml.silmaril.ie/