SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with code from "Build your own Ajax Web Applications" book - XMLParse

    Hi,

    Has anyone got all the example Ajax Web Apps to work? I am stuck on the example in Chapter 6: Web Services and Slide-and-hide. I have a valid Amazon Access Key ID.

    My code matches to book's downloadable code. Even if I 'cheat' and simply run the book's downloadable code, I get a problem with XMLParse.

    I am getting the following error:

    xmlDocElem has no properties in xmlparse.js

    Using Firebug to investigate, it appears that the first parameter being passed across is undefined/null.

    The code being used to call the xml2ObjArray is exactly the same as the "Call it like this:" comment.

    // Takes an array of XML items, transforms into an array of JS objects
    // Call it like this: res = XMLParse.xml2ObjArray(xml, 'Item');
    this.xml2ObjArray = function(xmlDocElem, tagItemName) {
    var self = XMLParse;
    var xmlElemArray = new Array;
    var xmlElemRow;
    var objArray = [];

    // Rows returned
    if (xmlDocElem.hasChildNodes()) {
    xmlElemArray = xmlDocElem.getElementsByTagName(tagItemName);
    xmlElemRow = xmlElemArray[0];
    // Create array of objects and set properties
    for (var j = 0; j < xmlElemArray.length; j++) {
    xmlElemRow = xmlElemArray[j];
    objArray[j] = self.xmlElem2Obj(xmlElemArray[j]);
    }
    }
    return objArray;
    };

    The JS library being used is an 'external' one: xmlparse.js. I assume it is being used with other web apps around the world outside of just this book.

    Has anyone else come across this problem? It is driving me crazy, since the rest of the book's code has been, for the most part, fantastic.

    Would more code snippets make it easier to help track down this problem? I didn't want to post all the source code because it is quite lengthy and most of it doesn't have anything to do with the problem.

    Thanks in advance for any pointers.

    Richard

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Using Firebug to investigate, it appears that the first parameter being passed across is undefined/null.
    Information flows both ways. Which direction are you talking about? The first 'parameter'? Functions have parameters. What do you mean by 'parameter'?

    xmlDocElem has no properties in xmlparse.js
    Post what is in the variable 'xml'.

  3. #3
    SitePoint Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi 7stud,

    Thanks for your reply. Sorry I forgot to include things. I hope this time will be more useful.

    Quote Originally Posted by 7stud View Post
    Information flows both ways. Which direction are you talking about? The first 'parameter'? Functions have parameters. What do you mean by 'parameter'?

    Post what is in the variable 'xml'.
    res = XMLParse.xml2ObjArray(xml, 'Item');

    xml is undefined.
    Edit: xml is null. Not undefined. My mistake.

    Code from webservice1.js

    Ajax call:
    self.ajax.doGet(uri, self.handleResp, 'xml');


    this.handleResp = function(xml) {
    var self = Client;
    var res = [];
    ...

    res = XMLParse.xml2ObjArray(xml, 'Item');

    I have attached the two js files I am using. Hope this is more use.
    Attached Files Attached Files
    Last edited by lockley; Mar 6, 2007 at 04:16.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try removing all quotes around 'xml'. When it's quoted it means 'xml' just a string made up of the the 3 characters x, m, and l. When it's not quoted, it means it's a variable that contains some data.

  5. #5
    SitePoint Member
    Join Date
    Oct 2004
    Location
    UK
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi 7stud,

    I've figured it out! Schoolboy/User error. I hadn't installed a required package from PEAR (HTTP_Request).

    Sorry for wasting your time.
    Thanks for the help anyway.

    Richard


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •