Adam Spice

Navigation

Skip navigation.

Search

Site navigation

Email conversation

FromAdam Spice
ToMe
SubjectError using XML Import script on all browsers
Date13 July 2009 03:58
Hi Taquin,

First of let me say thanks for writing the XML import script, it has made my
life much easier.

Bu I am getting errors when I use it. 

We have an application that the generates and XML file every 1.5 secs and
then users look at it via a webpage that uses your script to update. The
Ajax side seems to go Ok for a while but every now and then we get an error:

no element found
createTable(Document )stats.html (line 10)
onreadystatechange()
[URL]
Line 10

I have tried this on both IE8 and FF 3.0.11 and get the same error, I am
thinking it is due to a read write clash on the XML file. Any help you can
provide to stop this would be greatly appreciated

The page and source can be seen at 
[URL]

Regards

Adam Spice
FromMe
ToAdam Spice
SubjectRe: Error using XML Import script on all browsers
Date13 July 2009 07:57
Adam,

A few points:

1. You have removed my comments from the script source, which is a violation
of the license terms. See the license here:
http://www.howtocreate.co.uk/jslibs/termsOfUse.html

2. If you want me to debug a problem, it would really help if you don't wrap
it in a try...catch block, which will hide the error from me ;)

3. This error message is, unfortunately, completely meaningless:

> createTable(Document )stats.html (line 10)
> onreadystatechange()

4.
> I have tried this on both IE8 and FF 3.0.11

Please follow the instructions on my contact page:
http://www.howtocreate.co.uk/sendEmail.php#testbrowsers
IE and Firefox do not constitute "all browsers", and neither give a useful
error message. I need to see what Opera says when it sees the failure. (Make
sure you enable stacktraces first, and note that you can use shift+click to
select multiple lines for copying in the error console.)

5. I have live edited your source in Opera to remove the try...catch block
and tested it for ages without the error showing up. I cannot reproduce the
problem in other browsers either because of your try...catch block.

6. I suspect your problem is that the browser is requesting the XML page
while some server-side script is in the process of rewriting it. It looks
like a regular XML file so the only way I can see it being updated every few
seconds is that a server-side process updates it at intervals. If this is
the case, then the problem would occur whenever that process was part way
through writing that file at the instance that the browser requested it.
This would result in it retrieving a partially complete XML file, which
would fail to parse correctly, and cause the script to throw an error when
it failed to find the elements it was looking for.

There are three options if this is the case:

a. Use try...catch or a check for the root element to avoid the error, and
hope it will pick up a proper file next time around.

b. Instead of requesting an XML file, make a request to a server-side script
which prepares updated XML, and hands that to the browser. This will need
more processing power if you have lots of visitors.

c. Make sure you never write a partial XML file. Instead of opening it and
writing each line as it is prepared, prepare the entire file contents and
write them immediately, or write them in another file and quickly replace
the existing file with the new one.


Mark 'Tarquin' Wilton-Jones - author of http://www.howtocreate.co.uk/
This site was created by Mark "Tarquin" Wilton-Jones.
Don't click this link unless you want to be banned from our site.