Forum Moderators: open

Message Too Old, No Replies

XML and Firefox...what's up?

         

Acternaweb

3:04 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



I am a newbie, but am at a loss. I have a very simply xml/html page that works perfect in IE, but doesn't work at all in firefox.

I have been trying to find a site that will detail what other browsers have trouble with XML. Any ideas?

Hester

3:28 pm on Mar 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How is the page found? On the web, or on your computer for now? How is it served? As text/html or xml?

irnbru

3:33 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



From some of your previous posts it looks like your trying to mess with XML on the client side?

I would *strongly* advise against this and learn to use XML on the server-side.

But if you insist ...... google for ......

"XML data islands site:www.mozilla.org"

Acternaweb

3:33 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



It's a local page, I "browse" to the page

zooloo

3:36 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



Probably, though not always, the problem in not Firefox per se.

Is your code valid? Try the W3C validator to see. It may highlight the issue.

Firefox is standards compliant IE is not.

zoo

Acternaweb

5:17 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



irnbru

I am in a course, they have us working on a "simple" xml and html page. I do upload it to the server.

The code doesn't "validate" because I don't have a dtd. Is that why Ie will show it but not firefox?

irnbru

5:57 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



I'm guessing your fetching a xml file?

Does it contain something like

<?xml:stylesheet href="foobar.xsl" type="text/xsl"?>

or

<?xml-stylesheet href="foobar.xsl" type="text/xsl"?>

If the former change it the latter.

Otherwise I think your going to have to explain a bit more .....

Acternaweb

6:38 pm on Mar 15, 2005 (gmt 0)

10+ Year Member



hi

it is neither. this is what is in my .html file:
<xml id="movielist" src="movielist.xml"></xml>

Thanks

irnbru

11:12 am on Mar 16, 2005 (gmt 0)

10+ Year Member



You've got an XML data island. Please see message #3 in this thread.

Zephryl

10:08 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



Hi, I don't know if you're done with what you were working on, but I figured I could go ahead a post a possible solution to your problem. In my case, I needed only basic crossbrowser functions to use on an XML document, I went ahead and wrote my own since I couldn't find ones that agreed with both browsers(getElementsByTagName() just wouldn't work in IE) Anyway, here's my code:

var isIE = false;
if (window.ActiveXObject){
isIE = true;
}
function GetText(node){
if(isIE){
return node.text;
}else{
return node.textContent;
}
}
function GetByTagName(node, name){
var childArray = new Array();
for(var i=0; i<node.childNodes.length; i++){
if(node.childNodes[i].nodeName == name){
childArray[childArray.length] = node.childNodes[i];
}
}
return childArray;
}
var xmlDocVersions = new Array("Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "Msxml2.DOMDocument", "Microsoft.DOMDocument");
function push_GetXmlDoc(xml, index){
var xmlDoc=null;
if (window.ActiveXObject && index < xmlHttpVersions.length){
try{
xmlDoc = new ActiveXObject(xmlDocVersions[index]);
Debug("XML Doc Version: "+xmlDocVersions[index]+"<br>");
xmlDoc.async="false";
xmlDoc.loadXML(xml);
}catch(e){
push_GetXmlDoc(xml, index+1);
}
}
if (document.implementation.createDocument){
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xml, "text/xml");
}
if(xmlDoc == null) alert("XML Doc Load Failed");
return xmlDoc;
}

In my case, I'm getting XML over an XML HTTP Connection, so it's a string, not a file. In your case I believe the .load(XMLFILENAME); is crossbrowser supported. How I use the above code:

xmlDoc = GetXmlDoc(XMLSTRINGVARIABLE, 0).documentElement;
var tags = GetByTagName(xmlDoc, TAGNAMEASSTRING);
for(var t in tags){
alert(GetText(tags));
}

Some disclaimers/closing statements:
This could be extended to access attributes. GetByTagName is iterative so it's slower than using a browser supported function like .getElementsByTagName(). I'd love to think there's a better way and that someone will post it here. :-)

And last but not least! I use this code to get XML data with javascript and then affect the DOM. I'm hoping to use XSL in future coding, I believe it is an acceptable replacement(and a lot nicer), but need to learn it first.

Zephryl

6:19 pm on Apr 1, 2005 (gmt 0)

10+ Year Member



There's a slight error.

}catch(e){
push_GetXmlDoc(xml, index+1);
}

Should be:

}catch(e){
return push_GetXmlDoc(xml, index+1);
}