473,789 Members | 3,013 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trouble using mozilla xml loading code

Hi there,

I am using the following function to import a xml file whether the
users browser be IE or Mozilla:

function importXML(file) {
var xmlDoc;
var moz = (typeof document.implem entation != 'undefined') && (typeof
document.implem entation.create Document != 'undefined');
var ie = (typeof window.ActiveXO bject != 'undefined');

if (moz) {
xmlDoc = document.implem entation.create Document("", "", null)
//do I need something else here???
} else if (ie) {
xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
xmlDoc.async = false;
while(xmlDoc.re adyState != 4) {};
}
xmlDoc.load(fil e);
return xmlDoc
}

An example call of this function looks like this:

importXML('xml/books.xml')

The code for IE works well as I have used code to access the XML file
im using but the code for Mozilla doesnt work. I got the funxtion from
a tutorial site, http://www.sitepoint.com/article/xml-javascript-mozilla.

Am I missing something after the line 'xmlDoc =
document.implem entation.cre... ?? On the tutorial it had a line
xmlDoc.onload = readXML but that appears to be some kind of function,
readXML, and isnt shown on the tutorial. How do I get the variable
xmlDoc to the same stage as the code used for IE so that I can then
perform something like after the function is run??:

nodes = xmlDoc.getEleme ntsByTagName("t itle")

or

nodes = xmlDoc.document Element.childNo des
If I try the above in Mozilla and do something like nodes.length I get
0 (wrong) whereas if I do it in IE, I get 10 (correct). Is the 'nodes
= ...' code only able to run in IE or is the variable, xmlDoc, not
properly prepared in Mozilla to do the above?? The results I get in
Mozilla lead me to assume either but I may be wrong. Any help would be
great.

Cheers

Burnsy
Jul 23 '05 #1
1 1954


mr_burns wrote:

I am using the following function to import a xml file whether the
users browser be IE or Mozilla:

function importXML(file) {
var xmlDoc;
var moz = (typeof document.implem entation != 'undefined') && (typeof
document.implem entation.create Document != 'undefined');


Other browsers have document.implem entation.create Document as well so at
least the name of the variable 'moz' is doubtful.

While Mozilla allows you to create an XML document with the method you
check for above and then exposes a load method that stuff is Mozilla
only while by now Safari and recent Opera version implement
XMLHttpRequest thus I would strongly suggest to use that if you want to
load XML:

function loadXML (url, processXML) {
var httpRequest;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest( );
}
else if (typeof ActiveXObject != 'undefined') {
httpRequest = new ActiveXObject(' Microsoft.XMLHT TP');
}
if (httpRequest) {
httpRequest.ope n('GET', url, true);
httpRequest.onr eadystatechange = function () {
if (httpRequest.re adyState == 4 && httpRequest.res ponseXML) {
processXML(http Request.respons eXML);
}
};
httpRequest.sen d(null);
}
}

function exampleXMLHandl er (xmlDocument) {
if (xmlDocument.do cumentElement) {
alert(xmlDocume nt.documentElem ent.childNodes. length);
}
}
loadXML('test20 05010601.xml', exampleXMLHandl er)

That should do with IE/Win (versions 5, 5.5, 6 and hopefully later),
Mozilla 1.0 and later, Safari 1.2 (not tested now), Opera 7.6x , 8.00 or
later, as long as the XML loaded is well-formed. If the parsing of the
XML fails then unfortunately every implementation has its own way to
indicate parse errors so catering for that is a bit too much to handle
here in a newsgroup post.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6000
by: Peter | last post by:
Hello, First of all, sorry for all the code. I don't know how to explain my problem without it. I have a javascript function which can build a webpage dynamically. A striped down version of the function looks like this: BEGIN CODE
2
2213
by: Ola Fjelddahl | last post by:
hi. I load a script dynamically and it works * everytime with IE6. * sometimes! with Mozilla1.5 <- makes me curious * never with Opera7.11 all tests on WindowsXP. With "sometimes" I mean
3
2090
by: kj | last post by:
This problem is driving me nuts. The code at the end of this post below works fine with IE, but fails with Mozilla. You can see it in action at http://tinyurl.com/2jvo3 With Mozilla 1.4 and 1.6, the function msg works fine if it's installed as an onclick handler for the button, but fails as an onload handler for the page. The error is "console has no properties", and is triggered by the line.
4
1806
by: ekimnosnews | last post by:
I'm programming a JS tile map editor for my friend's game. The map editor has different "sections" that contain different tiles. The way that it works is when you select a section it calls a JS function that changes the src of a script tag that contains the array of tiles for that section, then reloads the tile selection table. This works great in IE, but Mozilla/Firefox doesn't update the array when I switch JS files. I've tried putting a...
17
3051
by: George Hester | last post by:
http://tinyurl.com/5uj6w The lower middle icon the "block" should not drop down when the mouse is over it. How can I stop that? Also the navigation divs both top and bottom should follow the scroll right. Both of these issues occur in IE 6 but not in IE 5.5. You can get the horizontal scroll bar for the window by increasing the size of the image wider than the display area of the window. Assumes 600x800 default display size. Thanks...
9
3819
by: johnd126 | last post by:
I have a cgi program which outputs a fairly hefty amount of html/javascript for doing a complex slide show sorta thing in a variety of areas in the browser. I accomplish this by creating a series of iframes and populating each iframe which its own copy of the code and a list of items to display. It previously had it working tickety-boo with both IE 6 and Firefox. I've had to concentrate on adding new features to the IE side and am now...
1
2342
by: newToAjax | last post by:
I have created an ajax application which retrievs an xml file and fills in the tab fields on the form.The code works fine in IE while its does not in Mozilla. Can you please let me know if i have to install some plugins to use XPATH? <html> <head> <title>SilverLine </title> <link rel="stylesheet" href="example.css" TYPE="text/css" MEDIA="screen"> <script type="text/javascript"> /* Optional: Temporarily hide the "tabber" class so it...
5
13383
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10408
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.