Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 30th, 2003, 02:33 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default XML and NN

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 :

Code:
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 :

Code:
<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 !!
__________________
All the best

Greg
------------------
Greg Griffiths
Web & Livelink Developer
http://www.greggriffiths.org





Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Server 2005 XML: FOR XML PATH -> cdata? stoves SQL Server 2005 1 July 8th, 2008 02:40 AM
xml invalid top level from ASP write XML(solution) g000we XML 0 August 9th, 2006 03:56 AM
DTS Package, XML task. Read XML file and store it Victoria SQL Server DTS 0 July 24th, 2006 02:43 PM
JavaScript & XML & NN lmod Javascript How-To 0 August 18th, 2005 03:16 PM
XML and NN Greg Griffiths Javascript 1 October 31st, 2003 06:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.