Holzner's book

Discussion in 'XML' started by steve.cpp, Oct 12, 2009.

  1. steve.cpp

    steve.cpp Guest

    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, Oct 12, 2009
    #1
    1. Advertising

  2. I don't think the <xml> tag is standard HTML...
     
    Joe Kesselman, Oct 13, 2009
    #2
    1. Advertising

  3. 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, Oct 13, 2009
    #3
  4. 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, Oct 13, 2009
    #4
  5. 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, Oct 13, 2009
    #5
  6. steve.cpp

    Peter Flynn Guest

    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, Oct 13, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SStory

    Re: book advice

    SStory, Jul 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    989
    SStory
    Jul 6, 2003
  2. Lenny

    Re: book advice

    Lenny, Jul 6, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    942
    SStory
    Jul 6, 2003
  3. Thanasis \(sch\)

    awt book+java animation book

    Thanasis \(sch\), Oct 13, 2004, in forum: Java
    Replies:
    1
    Views:
    625
    Alex Hunsley
    Oct 14, 2004
  4. coltrane
    Replies:
    2
    Views:
    506
    coltrane
    Sep 27, 2006
  5. Gio

    Puzzle Book & Answer Book

    Gio, Apr 17, 2008, in forum: C Programming
    Replies:
    1
    Views:
    406
    santosh
    Apr 17, 2008
Loading...

Share This Page