/    Sign up×
Community /Pin to ProfileBookmark

Parsing XML into HTML using javascript (FF2)

Cheers good folks,

I usually don’t post unless I cannot find the solution myself (like most folks) I have done some searching (google) and even currently have the w3c standard setup for my parsing script. However the script only works for I.E but not Firefox (2.x) which is odd seeying that the same xml script work for both on w3c.

Here is the link:
[url]http://members.chello.nl/~r.verbrugge/OKI/OKI.html[/url]

Clicking the ‘Training’ icon on the left bottom will add 3 new items to the menu (when using IE).
What is incorrect about this script and how can I fix it to work on Firefox?

My thanks for any help.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@lenny01Jan 16.2008 — Hi Shampie

Firefox does not support ActiveX. Put the ActiveX statement into the else-block or into a try-catch block:

you may modify your code like this:
[CODE]
if (document.implementation.createDocument)
{
xmlDocument = document.implementation.createDocument("", "", null);
}
else if(window.ActiveXObject)
{
xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
}
else
{
alert('Browser is not compatible with Netscape 6.0 or IE 5.0, cannot load xml!');
return;
}[/CODE]


cheers!

- lenny
Copy linkTweet thisAlerts:
@ShampieauthorJan 16.2008 — Hey Lenny,

Thank you for the reply.

I implemented the code you gave as:
[CODE]
if (document.implementation.createDocument)
{
xmlDoc = document.implementation.createDocument("", "", null);
alert("FF");
}
else if(window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
alert("IE");

}
else
{
alert('Browser is not compatible with Netscape 6.0 or IE 5.0, cannot load xml!');
return;
}

xmlDoc.async=false;
xmlDoc.load("data.xml");

xmlObj=xmlDoc.documentElement;
[/CODE]


Alerts show for there respective browsers however firefox doesn't do anything than display the alert message and IE works as before.

Other implementation for FF?

Cheers
Copy linkTweet thisAlerts:
@ShampieauthorJan 16.2008 — To follow up on the previous post:

this part
[CODE]
var list_len = xmlObj.getElementsByTagName("menu")[0].childNodes.length; //Firefox reads 7?! IE reads 3!


for (i = 0; i < list_len; i++){
alert(list_len);
[/CODE]

see comment above.

What is up with that???
Copy linkTweet thisAlerts:
@ggomvalApr 15.2009 — To get the same result in FireFox than in IE you have to write:

var elements = 0;

for( var i = 0; xmlDoc.documentElement.childNodes[i]; i++ ) { // Only IE

if ( xmlDoc.documentElement.childNodes.item(i).nodeType == 1 ) { // Extra Test needed for Firefox

elements++;

}

}



// Hope this help

// Guillermo Gómez Valcárcel
×

Success!

Help @Shampie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...