Go Back   Velocity Reviews > Newsgroups > XML
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

XML - Holzner's book

 
Thread Tools Search this Thread
Old 10-12-2009, 11:59 PM   #1
Default Holzner's book


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?


steve.cpp
  Reply With Quote
Old 10-13-2009, 03:54 AM   #2
Joe Kesselman
 
Posts: n/a
Default Re: Holzner's book
I don't think the <xml> tag is standard HTML...


Joe Kesselman
  Reply With Quote
Old 10-13-2009, 08:24 AM   #3
Johannes Koch
 
Posts: n/a
Default Re: Holzner's book
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.)


Johannes Koch
  Reply With Quote
Old 10-13-2009, 12:08 PM   #4
Martin Honnen
 
Posts: n/a
Default Re: Holzner's book
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/


Martin Honnen
  Reply With Quote
Old 10-13-2009, 07:02 PM   #5
Joe Kesselman
 
Posts: n/a
Default Re: Holzner's book
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.


Joe Kesselman
  Reply With Quote
Old 10-13-2009, 11:04 PM   #6
Peter Flynn
 
Posts: n/a
Default Re: Holzner's book
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/


Peter Flynn
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46