Click to See Complete Forum and Search --> : Javascript, XML and Mozilla


acohen
03-23-2004, 10:33 AM
Here's the problem:
I am developing a html page with an xml data island. I call an external xml file into a dynamically updated html table. It works fine in IE6. However the data stored in the xml file doesn't go into the table if I use Mozilla Firefox (and I assume Netscape Navigator).

My boss said that he only wants to support IE5,6 (poo on him). So I wrote a little javascript that detects users' browser and warns them to use IE. How would I get it to recognize IE, and not give any warning, yet warn anyone using any other browser to use IE? Here's what I have so far, but I am a bit stuck:

<head><meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>OCS</title>
<SCRIPT language="JavaScript">
<!--
var browserName=navigator.appName;
if (browserName=="Netscape")
{
alert("Netscape/Mozilla User: Please note that you must use Microsoft Internet Explorer 5 or up to view this page correctly");
}
else
{
alert("Please use Microsoft Internet Explorer 5 or up to view page correctly");
}
}
//-->
</SCRIPT>
</head>

I realize that not everyone has javascript enabled, but this is what the boss wants...

Vladdy
03-23-2004, 10:40 AM
Gecko engine supports XML straight up, so it should be easier to use it on your web page with Mozilla/Firebird/Netscape7/Firefox/etc than with IE.

Seems like you are doing something wrong there....

When I see a web page that tells me to use IE, I readily click the back button. So if your boss thinks its OK to ignore the increasing number of surfers who switch to better browser, I suggest you start looking for a new place to work, since business that ignores its customers does not usually survive very long....

acohen
03-23-2004, 11:01 AM
I agree. I will try to pursuade him otherwise. From what I just read the problem might be in the XML code, and IE fixes the problem, whereas Mozilla conforms more to standards. Am I correct in that assumption?

Vladdy
03-23-2004, 11:38 AM
Most probably, but it is hard to say without seeing the code or better yet a link to the page...

acohen
03-23-2004, 12:00 PM
Hi Vladdy:
The page is at:
http://www.cohencentral.com/projects/ocs_project/
-thanks.

Here's the XML file (tabledata.xml):
<?xml version="1.0" encoding="iso-8859-1"?>
<ROOT>
<ROOM>
<NUMBER>1770</NUMBER>
<TYPE>Classroom</TYPE>
<PC>yes</PC>
<DVD>yes</DVD>
<AUDIO>yes</AUDIO>
<VCR>no</VCR>
<SEATS>50</SEATS>
</ROOM>
<ROOM>
<NUMBER>1440</NUMBER>
<TYPE>Courtroom</TYPE>
<PC>no</PC>
<DVD>no</DVD>
<AUDIO>yes</AUDIO>
<VCR>no</VCR>
<SEATS>150</SEATS>
</ROOM>
<ROOM>
<NUMBER>1880</NUMBER>
<TYPE>Classroom</TYPE>
<PC>no</PC>
<DVD>no</DVD>
<AUDIO>yes</AUDIO>
<VCR>no</VCR>
<SEATS>150</SEATS>
</ROOM>
</ROOT>

Khalid Ali
03-23-2004, 12:07 PM
NS(mozilla 1>) browsers do support XML viewing and applying XSL/XSLT at run time,however,Mozilla did lack in having any functionality as incorprating XML data islands in IE.
Recently Mozilla has implemented some new functionality(mostly to cater web services) which can allow to read an xml file in the javascript just ad you would in IE using data islands.
unfortunately I have not been able to find any time to implement an example to show this functionality in MOZ(hope some one else has it done).
Or you can go at mozilla.org and look for it.
If you are not able to find a solution,ping me over the weekend and I might be able to put a working example together for all f you looking for this functionality in Mozilla

acohen
03-23-2004, 12:12 PM
Thanks Khalid! I will look at Mozilla.org and let you know what I find, or don't find. -Aaron

Vladdy
03-23-2004, 12:13 PM
No wonder, you are using some proprietory M$ technique to embed your XML document.

acohen
03-23-2004, 12:16 PM
Khalid:
I found something pointing to this at:
http://www.mozilla.org/xmlextras/xmldataislands/

Khalid Ali
03-23-2004, 12:26 PM
Originally posted by acohen
Khalid:
I found something pointing to this at:
http://www.mozilla.org/xmlextras/xmldataislands/

Not really,thats a popular work around to mimic the IE's data island functionality.

The new functionality works almost exactly as IE's data island...

acohen
03-23-2004, 12:55 PM
Vladdy:
I just found that out. Netscape browsers don't support data islands. One has to use javascript to get around it.

I've seen some examples online of how to do it, but the examples are only with internally embedded XML, not an xternal xml file. Do you know if this can be done. I need the xml to be an external file.

To be honest, I am new to XML and not a developer, just a graphic designer messing around. Any experience with this? Thanks, Aaron

Vladdy
03-23-2004, 01:07 PM
Just to import XML data you can use <object> element:
<object data="tabledata.xml" type="application/xml">
XML Data
</object>

You would need to include a stylesheet with your xml:
<?xml-stylesheet type="text/css" href="tabledata.css"?>
and add header column to it (unless you fix column widths in tabledata.css and put a table header with the same widths above the object tag).

Rudimentary CSS would look like this:

ROOT
{ display: table;
border-collapse: collapse;

}

BODY
{ display: table-row-group;
border: solid black 1px;
}

ROOM
{ display: table-row;
}

NUMBER,TYPE,PC,DVD,AUDIO,VCR,SEATS
{ display: table-cell;
padding: 0.5em;
border: solid black 1px;
}

I added BODY element to be styled as table body to keep things conforming...

Now the question remains how to combine it with IE version...
IE chokes on the object tag and displays nothing (which is good).
Ass IE code using their proprietory comment:
<!--IF IE ... (or something like that....)

Vladdy
03-23-2004, 01:16 PM
If you'd rather rely on JS to dynamically insert data into the page, use
XMLHttpRequest() object that reads and parses external XML file, so all you left to do is follow the XML tree and create corresponding table tree in your document...

acohen
03-24-2004, 11:59 AM
Thanks for your help. -A

Khalid Ali
03-27-2004, 08:16 PM
As promissed, here is the example that I have put together to show
XMLHttpReuest objects functionality for both NS6+ and IE5+ browsers.

The example will work when its residing on a web server(thats the intent of XMLHttpRequest object)

XMLHttpRequest Object Example (http://www.webapplikations.com/pages/html_js/xmlstuff/XMLHttpRequest.html)