NN and XML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Greg Griffiths

    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.imple mentation && document.implem entation.create Document)
    {
    xmldoc = document.implem entation.create Document("", "", null);
    }
    else if (window.ActiveX Object)
    {
    // create a new XML object for IE
    xmldoc=new ActiveXObject(" Microsoft.XMLDO M");
    }
    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('ne ws.xml');

    // load the moves
    newsItems = xmldoc.getEleme ntsByTagName("n ewselement");

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

    text[i]=newsItems[i].getElementsByT agName("headlin e")[0].firstChild.dat a;


    header[i]=newsItems[i].getElementsByT agName("newsite m")[0].firstChild.dat a;


    linka[i]=newsItems[i].getElementsByT agName("newslin k")[0].firstChild.dat a;


    targa[i]=newsItems[i].getElementsByT agName("newstar get")[0].firstChild.dat a;

    }


    with the XML file being used as follows :


    <newsticker>
    <newselement>
    <newsno>1</newsno>
    <headline>Thi s is Headline 1</headline>
    <newsitem>Thi s is NI 1</newsitem>
    <newslink>hello World.html</newslink>
    <newstarget>a </newstarget>
    </newselement>
    <newselement>
    <newsno>2</newsno>
    <headline>Thi s is Headline 2</headline>
    <newsitem>Thi s is NI 2</newsitem>
    <newslink>htt p://www.greggriffit hs.org/</newslink>
    <newstarget>new </newstarget>
    </newselement>
    <newselement>
    <newsno>3</newsno>
    <headline>Thi s is Headline 3</headline>
    <newsitem>Thi s is NI 3</newsitem>
    <newslink>htt p://www.greggriffit hs.org/</newslink>
    <newstarget>bla nk</newstarget>
    </newselement>
    </newsticker>


    Can anyone help me out with this as it is driving me nuts !!

  • Martin Honnen

    #2
    Re: NN and XML



    Greg Griffiths wrote:[color=blue]
    > 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.imple mentation && document.implem entation.create Document)
    > {
    > xmldoc = document.implem entation.create Document("", "", null);
    > }
    > else if (window.ActiveX Object)
    > {
    > // create a new XML object for IE
    > xmldoc=new ActiveXObject(" Microsoft.XMLDO M");
    > }
    > else
    > {
    > alert('Your browser can\'t handle this script');
    > }
    >
    > // define some attributes of the doc
    > xmldoc.async = false;[/color]

    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


    Comment

    • Greg Griffiths

      #3
      Re: NN and XML

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

      Martin Honnen wrote:
      [color=blue]
      > Greg Griffiths wrote:[color=green]
      > > 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.imple mentation && document.implem entation.create Document)
      > > {
      > > xmldoc = document.implem entation.create Document("", "", null);
      > > }
      > > else if (window.ActiveX Object)
      > > {
      > > // create a new XML object for IE
      > > xmldoc=new ActiveXObject(" Microsoft.XMLDO M");
      > > }
      > > else
      > > {
      > > alert('Your browser can\'t handle this script');
      > > }
      > >
      > > // define some attributes of the doc
      > > xmldoc.async = false;[/color]
      >
      > 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/[/color]

      Comment

      • Martin Honnen

        #4
        Re: NN and XML



        Greg Griffiths wrote:
        [color=blue]
        > Martin Honnen wrote:
        >
        >[color=green]
        >>Greg Griffiths wrote:
        >>[color=darkred]
        >>> 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.imple mentation && document.implem entation.create Document)
        >>>{
        >>> xmldoc = document.implem entation.create Document("", "", null);
        >>>}
        >>>else if (window.ActiveX Object)
        >>>{
        >>> // create a new XML object for IE
        >>> xmldoc=new ActiveXObject(" Microsoft.XMLDO M");
        >>>}
        >>>else
        >>>{
        >>> alert('Your browser can\'t handle this script');
        >>>}
        >>>
        >>>// define some attributes of the doc
        >>>xmldoc.asy nc = false;[/color]
        >>
        >>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
        >>asynchronou s 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.
        >>[/color]
        > can you amend my code, I'm having a little difficulty seeing where your
        > changes would go ?
        >[/color]

        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 processXMLDocum ent (evt) {
        alert(xmlDocume nt.documentElem ent.nodeName);
        // do here what you want to do with the document
        }
        var xmlDocument = document.implem entation.create Document('', '', null);
        xmlDocument.onl oad = processXMLDocum ent;
        xmlDocument.loa d('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


        Comment

        Working...