Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Holzner's book

Reply
Thread Tools

Holzner's book

 
 
steve.cpp
Guest
Posts: n/a
 
      10-12-2009
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?
 
Reply With Quote
 
 
 
 
Joe Kesselman
Guest
Posts: n/a
 
      10-13-2009
I don't think the <xml> tag is standard HTML...
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      10-13-2009
Joe Kesselman schrieb:
> I don't think the <xml> tag is standard HTML...


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.)
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      10-13-2009
steve.cpp wrote:

> <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/
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      10-13-2009
Johannes Koch wrote:
> So an element type xml (<xml id="firstXML" src="hello.xml"></xml>) is
> not allowed in XML-based languages.


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.
 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      10-13-2009
steve.cpp wrote:
> 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>


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/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Book report (it took me 16 years to read the book ) Mara Computer Support 4 04-11-2008 03:35 PM
Re: Book report (it took me 16 years to read the book ) VanguardLH Computer Support 0 04-10-2008 03:13 PM
Does anyone got the e-book for the book MCTS Training Kit (70-528) =?Utf-8?B?WWlu?= MCSD 0 11-18-2006 03:30 AM
"Java Performance Tuning Book" anyone read this book? coltrane Java 2 09-27-2006 01:13 PM
awt book+java animation book Thanasis \(sch\) Java 1 10-14-2004 03:02 PM



Advertisments