Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > XML access voor Firefox

Reply
Thread Tools

XML access voor Firefox

 
 
littlefool
Guest
Posts: n/a
 
      11-21-2005
Hi,

I'm trying to access a XML file in Firefox. It works perfect in IE
(with the ActiveXObject), but in Firefox displays it an empty page. I
found on the web examples how to do that, but I still have problems
with it. Can anyone help me with this?

This is the XML-file
<?xml version="1.0" encoding="UTF-8"?>
<constituencyseats>
<seat>
<Region>Central Scotland</Region>
<Constituency>Aidrie and Shotts</Constituency>
<Party>Labour</Party>
</seat>
<seat>
<Region>Central Scotland</Region>
<Constituency>Coatbridge and Chryston</Constituency>
<Party>Labour</Party>
</seat>
</constituencyseats>

This is the the code

this.xmlObj = loadXMLSeats('scripts/xml/Constituencyseats.xml',
'seat');

function loadXMLSeats(xmlFile, tagname){
var xmlDoc;
if(document.implementation && document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.onreadystatechange=verify;
}
else {
alert('your browser can\'t handle this script');
return;
}
xmlDoc.load(xmlFile);
return xmlDoc.getElementsByTagName(tagname);
}
function verify(){
// 0 Object is not initialized
// 1 Loading object is loading data
// 2 Loaded object has loaded data
// 3 data from object can be worked with
// 4 Object completely initialized
if (xmlDoc.readyState != 4) return false;
}

It appears that in Firefox the problem occurs with loading the XML
file. After loading, the object stays empty.

Thank you for your help

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      11-21-2005


littlefool wrote:


> I'm trying to access a XML file in Firefox. It works perfect in IE
> (with the ActiveXObject), but in Firefox displays it an empty page. I
> found on the web examples how to do that, but I still have problems
> with it.


Look here for suggestions on how to to that:
<http://www.faqts.com/knowledge_base/view.phtml/aid/6826/fid/616>


> var xmlDoc;
> if(document.implementation && document.implementation.createDocument)
> {
> xmlDoc = document.implementation.createDocument("", "", null);
> }


There are more browsers than Mozilla that support the above but a load
method is only exposed by some Mozilla versions thus that call

> xmlDoc.load(xmlFile);


will give an error in Opera for instance.

As for the Mozilla problem loading by default happens asynchronously so
you would need to set up an onload handler before calling the load
method. Or in newer Mozilla versions you can do synchronous loading by
setting
xmlDoc.async = false
before calling the load method. But synchronous loading blocks the
browser so it might be fine for a first test to play with XML, in your
final code on the web you should use asynchronous loading.

But check the article I linked to above, it is not necessary and helpful
to go the createDocument/load way for Mozilla as it does not work in
other browser at all while XMLHttpRequest to load XML works in lots of
browsers by now and gives you more possibilities and better error
handling (e.g. access to HTTP headers).

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Cees bedankt voor Guus meeuwis. annama11 annama11 Computer Support 0 11-21-2004 08:58 PM
[In Dutch] XML 2004 Award voor ''Best Powered XML Site'' Netherlands Pim van der Eijk XML 1 10-21-2004 06:11 PM
Random mac address assigned voor BVI ? Ronald de Leeuw Cisco 4 10-09-2004 05:59 PM
is tiscali geschikt voor xnews Rijndert Computer Support 1 12-26-2003 11:36 PM
hulp voor een toshiba die niets doet Steven Pilbeam Computer Support 7 07-11-2003 04:34 AM



Advertisments