Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Loading XML data Firefox problems
Old 07-23-2008, 08:00 AM Loading XML data Firefox problems
Novice Talker

Posts: 10
Trades: 0
Hi, I'm having problems loading data from an XML file.
It works fine with IE and Safari. It also works fine with Firefox provided I browse the files on my local drive. However, when i upload the files to the server and browse via the internet, Forefox doesn't perform as it should. Has anyone had this problem? Thanks.
It seems to go wrong after the line:
HeadingTpe = Heading[j].substring(0,1);

Scripts:

// JScript File
Heading = ["?. Incomplete","A. Corporate Strategy","B. Organisational Effectiveness",
"C. Operational Effectiveness","D. Business Tools"];
var xmlFile ='tipFile.xml';
var xmlDoc = null;
var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari/') != -1) { // code for Safari, use XMLHttpRequest() instead of .load()
XmlHTTP = new XMLHttpRequest();
XmlHTTP.open('get', xmlFile, false);
XmlHTTP.send('');
xmlDoc = XmlHTTP.responseXML;}
else if (window.ActiveXObject) { // code for IE
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(xmlFile);}
else if (document.implementation.createDocument) { // code for Mozilla, Firefox, Opera, etc.
xmlDoc = document.implementation.createDocument('','',null) ;
xmlDoc.async = false;
xmlDoc.load(xmlFile);}
else{
alert('Your browser JavaScript is enabled, but it cannot handle this script');
}
if (xmlDoc != null){
var x = xmlDoc.getElementsByTagName("tip");
for (j=1;j<=4;j++){
document.write('<li>' + Heading[j].substr(3,Heading[j].length) + '<ol class = "L4">');
HeadingTpe = Heading[j].substring(0,1);
for (i=0;i<x.length;i++){
type = x[i].getElementsByTagName('type')[0].firstChild.nodeValue;
file = x[i].getElementsByTagName('file')[0].firstChild.nodeValue;
title = x[i].getElementsByTagName('title')[0].firstChild.nodeValue;
TipDte = file.substring(6,8) + file.substring(9,11);
if (type == HeadingTpe){
document.write('<li><a href = "' + file +'">'+ title + '</a></li>' );
}
}
document.write('</ol></li>');
}
}
/*
--------------------------------------------------------------------------
This is a short version of 'tipFile.xml'
--------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<dataset>
<tip>
<title>Excel in Electronics - Resistor and Capacitor Marking Codes.</title>
<file>tip_2007_12.html</file><type>D</type></tip>
<tip>
<title>Vision and Mission.</title>
<file>tip_2008_01.html</file><type>A</type></tip>
<tip>
<title>Surrogate Performance Measurements - MSGc and PI.</title>
<file>tip_2008_02.html</file><type>C</type></tip>
<tip>
<title>Field Force Effectiveness.</title>
<file>tip_2008_03.html</file><type>B</type></tip>
</dataset>
--------------------------------------------------------------------------
The HTML file to load the 'ShowXML.js'
--------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhml1/DTD/xhml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>yada yada</title>
</head>
<body>
<h2>
Tips from previous months</h2>
<script language="JavaScript" type="text/javascript" src="ShowXML.js"></script>
</body>
</html>
--------------------------------------------------------------------------
*/
Jackson#1 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-25-2008, 10:01 PM Re: Loading XML data Firefox problems
Novice Talker

Posts: 10
Trades: 0
Hi,

After turning grey, I decided to take another approach. I now have all browsers behaving. Thanks for all who put their heads to the wheel.

Jackson.
Jackson#1 is offline
Reply With Quote
View Public Profile
 
Old 07-29-2008, 01:09 PM Re: Loading XML data Firefox problems
Novice Talker

Posts: 10
Trades: 0
Hi guys,

If anyone is interested, I did manage to get this to work. At least in Firefox, IE and Safari on a Windows environment. I'd be interested to hear if it falls over on any other platform. (obviously the links go nowhere in this demo).

ShowXML.js

// JScript File

function GetXMLdoc(xmlFile){
xmlDoc.async = false;
xmlDoc.load(xmlFile);
}
function loadXML(xmlFile){
if (window.ActiveXObject) {// code for IE
try {xmlDoc = new ActiveXObject("Msxml2.XMLHTTP"); // newer IE
GetXMLdoc(xmlFile);}
catch(e){
try{xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); // older IE
GetXMLdoc(xmlFile);}
catch(e){}}} // exit without xmlDoc}
else if (window.XMLHttpRequest) { // Mozilla, Safari,...
xmlHTTP = new XMLHttpRequest();
if (xmlHTTP.overrideMimeType) {xmlHTTP.overrideMimeType('text/xml')}
xmlHTTP.open('get', xmlFile, false);
xmlHTTP.send('');
xmlDoc = xmlHTTP.responseXML;}
else if (document.implementation.createDocument) { // code for other
xmlDoc = document.implementation.createDocument('','',null) ;
GetXMLdoc(xmlFile);}
else{
alert('Your browser JavaScript is enabled, but cannot handle this script');// if all else fails display message
}
}
var xmlDoc = null;
loadXML('tipFile.xml');
if (xmlDoc != null){
var doc = document.title;
var len = doc.length;
Dte = new Date();
var MaxDte = Dte.getFullYear() + '';
var Mth = '0' + (Dte.getMonth() + 1);
var heading = xmlDoc.getElementsByTagName('heading');
var x = xmlDoc.getElementsByTagName('tip');
MaxDte = MaxDte.substring(2,4) + Mth.substring(Mth.length-2,Mth.length);
for (j=1;j<=4;j++){
h = heading[j].firstChild.nodeValue;
document.write('<li>' + h.substr(3,h.length) + '<ol class = "L4">');
HeadingTpe = h.substring(0,1);
for (i=0;i<x.length;i++){
type = x[i].getElementsByTagName('type')[0].firstChild.nodeValue;
file = x[i].getElementsByTagName('file')[0].firstChild.nodeValue;
title = x[i].getElementsByTagName('title')[0].firstChild.nodeValue;
TipDte = file.substring(6,8) + file.substring(9,11);
if (type == h.substring(0,1)){
if (TipDte <= MaxDte){
document.write('<li><a href = "' + file +'">'+ title + '</a></li>' );
}
}
}
document.write('</ol></li>');
}
}


ShowXML.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhml1/DTD/xhml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>showXML.html</title>

</head>
<body>

<noscript><h3 style="color:Red;">* Features of this page require JavaScript to be enabled on your browser.</h3></noscript>

<script language="JavaScript" type="text/javascript" src="ShowXML.js"></script>

<div id="copyright">© 2008 Double Helix Group Pty Ltd<br />www.doublehelixgroup.com.au</div>

</body>
</html>

tipFile.xml

<?xml version="1.0" encoding="utf-8" ?>
<dataset>
<heading>?. Incomplete</heading>
<heading>A. Corporate Strategy</heading>
<heading>B. Organisational Effectiveness - people</heading>
<heading>C. Operational Effectiveness - processes</heading>
<heading>D. Business Tools</heading>
<tip>
<title>Excel in Electronics - Resistor and Capacitor Marking Codes.</title>
<file>tip_2007_12.html</file><type>D</type></tip>
<tip>
<title>Vision and Mission.</title>
<file>tip_2008_01.html</file><type>A</type></tip>
<tip>
<title>Surrogate Performance Measurements - MSGc and PI.</title>
<file>tip_2008_02.html</file><type>C</type></tip>
<tip>
<title>Field Force Effectiveness.</title>
<file>tip_2008_03.html</file><type>B</type></tip>
<tip>
<title>Grid lines in Excel Spreadsheets.</title>
<file>tip_2008_04.html</file><type>D</type></tip>
<tip>
<title>"NeHTA", "NPC" and "GS1" in the Pharmceutical Industry.</title>
<file>tip_2008_05.html</file><type>C</type></tip>
<tip>
<title>What is a Corporate Strategy Map?</title>
<file>tip_2008_06.html</file><type>A</type></tip>
<tip>
<title>Statistical Significance Explained.</title>
<file>tip_2008_07.html</file><type>D</type></tip>
<tip>
<title>Problem Solving - The missing hole puzzle.</title>
<file>tip_2008_08.html</file><type>D</type></tip>
</dataset>
Jackson#1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Loading XML data Firefox problems
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.26265 seconds with 12 queries