Wrox Programmer Forums
|
BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0
This is the forum to discuss the Wrox book Professional JavaScript for Web Developers by Nicholas C. Zakas; ISBN: 9780764579080
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2005, 03:24 PM
Registered User
 
Join Date: Oct 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML Retrieval Help

Hi I'm working on using an example out of the book on retrieving XML and I'm starting to get really turned around in making it work for Mozilla. I am also wondering if I could use the oXmlDom.getElementByTagName() method but for some reason when I do that I get an error. It tells me that oXmlDom has no properties. I'm new to all the XML and javascript world so I'm not sure what I'm doing wrong. But here is a current code example of what I'm working on:


Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
        <title>Cross-Browser XML DOM Example</title>
        <script type="text/javascript" src="scripts/detect.js"></script>

        <script type="text/javascript" src="scripts/xmldom.js"></script>

          <style type="text/css">
            body {
                font-family: "Trebuchet MS", Arial, Helvetica;
                font-size: 10pt;
            }
            .msg {
                width: 500px;
                font-family:"Trebuchet MS", Arial, Helvetica;
                border: 3px solid #ccc;
                padding: 10px;
            }
            html>body .msg {
                width: 490;
            }
            .line {
                border-bottom: 2px solid grey;
                width: 600px;
            }
            .codeMsg {
                font-style: italic;
                font-weight: bold;
                color: #CC3366;
            }
        </style>
    </head>
    <body>
        <p>
            This example loads a valid XML file and displays an alert showing us what 
            the root element is and how many child nodes there are.
        </p>
        <script type="text/javascript">
            var oXmlDom = new XmlDom();
            oXmlDom.onreadystatechange = function () {
                if (oXmlDom.readyState == 4) {

                    if (oXmlDom.parseError != 0) {
                        var oError = oXmlDom.parseError;
                        alert("An error occurred:\nError Code: "
                        + oError.errorCode + "\n"
                        + "Line: " + oError.line + "\n"
                        + "Line Pos: " + oError.linepos + "\n"
                        + "Reason: " + oError.reason);

                    }
                }
            };

            // Load the xml
            var    file    =    "xml/e_learning.xml";
            oXmlDom.load(file);
        </script>
        <h3>Message that XML document has loaded</h3>
        <div class="msg">
            <script type="text/javascript" language="javascript">
                if(isMoz)
                {
                    oXmlDom.onload    =    document.write('The XML file: <span class=\"codeMsg\">'+file+'</span> has been loaded');
                }
            </script>
        </div>

        <h3>We are testing the existance of: <span class="codeMsg">oXmlDom</span></h3>
        <div class="msg">
            <div class="codeMsg">
                <script type="text/javascript" language="javascript">
                    document.write(oXmlDom);
                </script>
            </div>
            <br />
            <script type="text/javascript" language="javascript">


                var oEvaluator = new XPathEvaluator();
            var oResult = oEvaluator.evaluate("welcome/title", oXmlDom.documentElement, null, XPathResult.STRING_TYPE, null);

            //alert(oResult.stringValue);
            document.write(oResult.stringValue);
            </script>
        </div>
 
    </body>
</html>
My xml document is (e_learning.xml) in the folder "xml":
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<course>
    <welcome>
        <title>C17 FEDS</title>
    </welcome>
</course>
I'm trying to get to the title...so how do I do this?

When running this code i get this error
Code:
Error: uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIDOMXPathEvaluator.evaluate]"  nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)"  location: "JS frame :: file:///Macintosh%20HD/Documents/Business/Intrepid/Projects/excel_to_xml/CrossBrowserXmlDomExample2.html :: <TOP_LEVEL> :: line 82"  data: no]
What am I doing wrong?






Similar Threads
Thread Thread Starter Forum Replies Last Post
Date retrieval Neal Excel VBA 1 February 1st, 2007 06:43 AM
For XML data retrieval fancorning4 SQL Server 2000 2 May 18th, 2006 10:33 AM
DropDownList selectedindex retrieval poison_king ASP.NET 1.0 and 1.1 Professional 5 September 21st, 2004 09:44 AM
Binary storage and retrieval acm54 SQL Server ASP 0 January 26th, 2004 10:30 PM
Data retrieval using MySQL rajanikrishna Beginning PHP 2 November 12th, 2003 11:38 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.