Adrian J. Batson

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromAdrian J. Batson
ToMe
SubjectNeed help implementing importxml.js
Date20 October 2008 05:58
Forgive me if my terminology and knowledge is a little flimsy, I'm fairly
inexperienced with web design/coding.

I had built my website ([URL]) using a pretty
simple script copied from [URL] to parse a long .xml file containing
information about 100+ images. My site is basically an online portfolio; I
used xml because I need to be able to dynamically reorder all the images
based on date or medium or whatever the user would like to sort them as, as
well as jump to specific categories.

When developing it, I only really tested it in Firefox (probably a mistake).
However, once I decided to test it in Safari, I got the error:

"Value undefined (result of expression xmlDoc.load) is not object."

As it stands my site works in these browsers (I downloaded and checked
additional browsers you reccomended):

Safari    3.1.2    No
Firefox    3.0.3    Yes
Opera    9.6    Yes
iCab    4.2.5    No

Also, Safari and iCab give me the exact same error (word for word).


Long story short, I stumbled across your script and implemented it as best I
could based on your comments. When I used it, I didn't use the function
(initially 'runThis') argument. I'm not sure what it would be used for or if
I need to use it to get things working.

var xmlDoc = importXML( 'images.xml');

Only a small part of the page loads when I un-comment it in my code.

 Hopefully what I'm doing wrong is something silly and an easy fix. Thanks
for any help you're willing to give on your script or even the one I'm using
already.

-- Adrian J. Batson
FromMe
ToAdrian J. Batson
SubjectRe: Need help implementing importxml.js
Date26 October 2008 10:54
Adrian,

> I'm fairly inexperienced with web design/coding.

And yet you try something complicated like importing XML ;)

> I had built my website using a pretty simple script to parse a long
> .xml file

The script you are currently using relies on an outdated approach that was
used only in a draft of a specification that was since abandoned.

> However, once I decided to test it in Safari, I got the error:

Yes, Safari does not support the abandoned draft. All current browsers use
XMLHttpRequest instead.

> Also, Safari and iCab give me the exact same error (word for word).

iCab 4+ uses Safari's engine. Good point - there is no need to test in it
any more :)

> var xmlDoc = importXML( 'images.xml');

This is not how the script works. It cannot just load and immediately give
you the resulting document. It loads the XML asynchronously (meaning that it
loads it in the background, then once it is ready, it will give the
resulting document to the script, but that can happen many seconds later, by
which time the original script has stopped running).

(XMLHttpRequest can load synchronously instead of asynchronously, but not
all browsers support that very well, and most of them will appear to hang or
lock up while it is loading.)

This is what you need to do:

Remove everything from this line:
var xmlDoc
up to this line:
var imageList = xmlDoc.getElementsByTagName("IMGS");

And replace it with this:
function prepareImageList(xmlDoc) {
  imageList = xmlDoc.getElementsByTagName('IMGS');
  sorter(1);
  displayImageRow();
  portImage(0);
}
var imageList = []; //to prevent errors if other functions try to use it
importXML( 'images.xml', 'prepareImageList' );

Then remove the body's onload attribute.

Note also that your onload attribute was wrong:
<body onload="sorter(1), displayImageRow(), portImage(0)">
The commas should have been semicolons.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
FromAdrian J. Batson
ToMe
SubjectRe: Need help implementing importxml.js
Date26 October 2008 16:27
Awesome! Works perfectly. Thank you so much for your time. =)
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.