469,356 Members | 1,930 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

NN and XML

Dear All,
I've got a small JS app that uses XML and I've got it working fine
in IE, but not in NN, I've used plenty of the samples on the web with my
Netscape Communicator and NN 6.1 but they just to seem to solve the
problem. The relevant code is below :
var text = new Array();
var header = new Array();
var linka = new Array();
var targa = new Array();
var newsItems;

// create an XMLDoc
var xmldoc;

if (document.implementation && document.implementation.createDocument)
{
xmldoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject)
{
// create a new XML object for IE
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
}
else
{
alert('Your browser can\'t handle this script');
}

// define some attributes of the doc
xmldoc.async = false;

//load the XML file in
xmldoc.load('news.xml');

// load the moves
newsItems = xmldoc.getElementsByTagName("newselement");

// populate the Move Arrays from the XML file
for (var i=0;i<newsItems.length;i++)
{
// add the move

text[i]=newsItems[i].getElementsByTagName("headline")[0].firstChild.data;
header[i]=newsItems[i].getElementsByTagName("newsitem")[0].firstChild.data;
linka[i]=newsItems[i].getElementsByTagName("newslink")[0].firstChild.data;
targa[i]=newsItems[i].getElementsByTagName("newstarget")[0].firstChild.data;

}
with the XML file being used as follows :
<newsticker>
<newselement>
<newsno>1</newsno>
<headline>This is Headline 1</headline>
<newsitem>This is NI 1</newsitem>
<newslink>helloWorld.html</newslink>
<newstarget>a</newstarget>
</newselement>
<newselement>
<newsno>2</newsno>
<headline>This is Headline 2</headline>
<newsitem>This is NI 2</newsitem>
<newslink>http://www.greggriffiths.org/</newslink>
<newstarget>new</newstarget>
</newselement>
<newselement>
<newsno>3</newsno>
<headline>This is Headline 3</headline>
<newsitem>This is NI 3</newsitem>
<newslink>http://www.greggriffiths.org/</newslink>
<newstarget>blank</newstarget>
</newselement>
</newsticker>
Can anyone help me out with this as it is driving me nuts !!

Jul 20 '05 #1
3 2937


Greg Griffiths wrote:
I've got a small JS app that uses XML and I've got it working fine
in IE, but not in NN, I've used plenty of the samples on the web with my
Netscape Communicator and NN 6.1 but they just to seem to solve the
problem. The relevant code is below :

// create an XMLDoc
var xmldoc;

if (document.implementation && document.implementation.createDocument)
{
xmldoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject)
{
// create a new XML object for IE
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
}
else
{
alert('Your browser can\'t handle this script');
}

// define some attributes of the doc
xmldoc.async = false;


This is the problem, Netscape 6.1 doesn't support async so what you need
for Netscape/Mozilla is an onload handler
xmldoc.onload = function (evt) {
// access document here
}

I think recent versions of Mozilla (since 1.4) support async but you
shouldn't rely on having a Mozilla 1.4 or 1.5 user on a Web page. Indeed
asynchronous loading is much more user friendly.

An alternative way to load XML documents is the
XMLHttpRequest
object (similar to MSXML XMLHTTP), this allows synchronous loading even
with earlier Mozilla/Netscape versions.
--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
Martin,
can you amend my code, I'm having a little difficulty seeing where your
changes would go ?

Martin Honnen wrote:
Greg Griffiths wrote:
I've got a small JS app that uses XML and I've got it working fine
in IE, but not in NN, I've used plenty of the samples on the web with my
Netscape Communicator and NN 6.1 but they just to seem to solve the
problem. The relevant code is below :

// create an XMLDoc
var xmldoc;

if (document.implementation && document.implementation.createDocument)
{
xmldoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject)
{
// create a new XML object for IE
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
}
else
{
alert('Your browser can\'t handle this script');
}

// define some attributes of the doc
xmldoc.async = false;


This is the problem, Netscape 6.1 doesn't support async so what you need
for Netscape/Mozilla is an onload handler
xmldoc.onload = function (evt) {
// access document here
}

I think recent versions of Mozilla (since 1.4) support async but you
shouldn't rely on having a Mozilla 1.4 or 1.5 user on a Web page. Indeed
asynchronous loading is much more user friendly.

An alternative way to load XML documents is the
XMLHttpRequest
object (similar to MSXML XMLHTTP), this allows synchronous loading even
with earlier Mozilla/Netscape versions.

--

Martin Honnen
http://JavaScript.FAQTs.com/


Jul 20 '05 #3


Greg Griffiths wrote:
Martin Honnen wrote:

Greg Griffiths wrote:
I've got a small JS app that uses XML and I've got it working fine
in IE, but not in NN, I've used plenty of the samples on the web with my
Netscape Communicator and NN 6.1 but they just to seem to solve the
problem. The relevant code is below :

// create an XMLDoc
var xmldoc;

if (document.implementation && document.implementation.createDocument)
{
xmldoc = document.implementation.createDocument("", "", null);
}
else if (window.ActiveXObject)
{
// create a new XML object for IE
xmldoc=new ActiveXObject("Microsoft.XMLDOM");
}
else
{
alert('Your browser can\'t handle this script');
}

// define some attributes of the doc
xmldoc.async = false;


This is the problem, Netscape 6.1 doesn't support async so what you need
for Netscape/Mozilla is an onload handler
xmldoc.onload = function (evt) {
// access document here
}

I think recent versions of Mozilla (since 1.4) support async but you
shouldn't rely on having a Mozilla 1.4 or 1.5 user on a Web page. Indeed
asynchronous loading is much more user friendly.

An alternative way to load XML documents is the
XMLHttpRequest
object (similar to MSXML XMLHTTP), this allows synchronous loading even
with earlier Mozilla/Netscape versions.

can you amend my code, I'm having a little difficulty seeing where your
changes would go ?


For the Netscape/Mozilla solution you simply need to put the code that
processes the XML document into a function which you set as an onload
event handler before you call the load method:

function processXMLDocument (evt) {
alert(xmlDocument.documentElement.nodeName);
// do here what you want to do with the document
}
var xmlDocument = document.implementation.createDocument('', '', null);
xmlDocument.onload = processXMLDocument;
xmlDocument.load('test20031030.xml')
As for an IE and Netscape example for that I think it is better to set
up some functions that do the work, I will see if I have the time to
come up with an example later.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by William C. White | last post: by
2 posts views Thread by Albert Ahtenberg | last post: by
3 posts views Thread by James | last post: by
reply views Thread by Ollivier Robert | last post: by
1 post views Thread by Richard Galli | last post: by
4 posts views Thread by Albert Ahtenberg | last post: by
1 post views Thread by inderjit S Gabrie | last post: by
2 posts views Thread by Jack | last post: by
3 posts views Thread by Sandwick | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.