Click to See Complete Forum and Search --> : javascript dom /load xml netscape


7gods1
05-09-2003, 01:52 PM
Hi guys,

Well i am having one tough time getting an xml document to laod in an html document. All i want to do is to access the data from the xml document. I have no problems setting up activexobject or data islands for ie. IE gives me no hassles. Netscape on the other hand is fighting me tooth and nail. Primarily because I probably don't know the correct method of handling it with netscape. Here is the sample code I am using from a text book for my test:


meetings.xml

<?xml version="1.0"?>
<meetings>
<meeting type="informal">
<meeting_title>xml in the real world</meeting_title>
<meeting_number>2079</meeting_number>
<subject>xml</subject>
<date>6/1/2002</date>
<people>
<person attendance="present">
<first_name>Edward</first_name>
<last_name>Samson</last_name>
</person>
<person attendance="absent">
<first_name>Ernestine</first_name>
<last_name>Johnson</last_name>
</person>
<person attendance="present">
<first_name id="betty">Betty</first_name>
<last_name>Richardson</last_name>
</person>
</people>
</meeting>
</meetings>

readxml.html:

<html>
<head>
<title>Read xml document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function Netscape()
{
var meeting,text;
meeting = xmlDoc.getElementsByTagName('meeting_title');
text = meeting.firstChild.nodeValue;
alert(text);

}

function getXml()
{
if(document.implementation && document.implementation.createDocument)
{
var xmlDoc;
xmlDoc = document.implementation.createDocument("","",null);
xmlDoc.onload = Netscape;
xmlDoc.load('meetings.xml');
}
}
</script>
</head>

<body>

<input type="button" value="test" onClick="getXml();" />

khalidali63
05-09-2003, 02:13 PM
I dont think you can use data island in NS,( I hope I did not miss anything )
You might want to use XSL if thats a possibility

7gods1
05-09-2003, 02:16 PM
I don't want to set up data islands. I just want to load the xml document and be able to pull data from the nodes into the html document. I have searched the net on loading xml documents and for netscape they showed this way of handling it. So i am unsure of what i am doing wrong.

7

khalidali63
05-09-2003, 02:21 PM
Lets see,It makes sense for me..
:D

7gods1
05-09-2003, 02:25 PM
That's the part that drives me bonkers. Looks fine, but no data. I should have an alert that states "xml in the real world". If you copy and paste the code into files on your drive, does it work?

7

khalidali63
05-09-2003, 02:39 PM
Here I think this is how it will work for both IE and NS,its actually prety neet the way I just did it,never thought about it before..lol

http://68.145.35.86/skills/javascripts/xmlstuff/XMLIslandWorkaroundForNS.html

7gods1
05-09-2003, 03:03 PM
WOW...GOOD JOB. In a way you have created a data island for netscape. COOL. One more question. Do you think the src property would work for external documents? I copied and pasted the code and added the src property. it doesn't pick it up. Maybe the property isn't src?

7

khalidali63
05-09-2003, 03:28 PM
<xml> tag is only supported by IE as of today,therefore src will not work for NS,and in the solution I wrote,you do not need src for that,it works for both NS and IE browsers without src.
This solution is actually better in a way that you do not need any activex control,you just use built in DOM methods.The only possible drawback will be that your xml document is in the html document.

7gods1
05-09-2003, 03:46 PM
thanks alot,

7

khalidali63
05-09-2003, 03:49 PM
You are welcome....:D