XML DOM in IE using Javascript

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

    #1

    XML DOM in IE using Javascript

    I am tryint to view a xml document in Internet Exploer as a ActiveX
    object using Javascript but it does not work. I only see the button
    but nothing happens when i click it. I am trying to view the
    'firstChild' of the xml document.

    here is the code;
    ----------------------------------------------------------------


    <html>
    <head>
    <script language="javas cript">
    <!--
    function alert()
    {

    var xmldoc, meetingsNode, meetingNode;
    xmldoc = new ActiveXObject(" Microsoft.XMLDO M");
    xmldoc.load("me mbers.xml");
    document.write( "works so far");

    meetingsNode = xmldoc.document Element;
    document.write( "works so far");


    meetingNode = meetingsNode.fi rstChild;
    //does not process after this line

    document.writel n(meetingNode);

    }
    //-->
    </script>



    <title>Read Members.xml</title>


    </head>

    <body>

    <input type="button" name="submit" onclick="alert( )" />



    </body>
    </html>
  • Jeff North

    #2
    Re: XML DOM in IE using Javascript

    On Sat, 23 Apr 2005 14:51:50 -0700, in comp.lang.javas cript Kenneth
    <jagger7774@hot mail.com> wrote:
    [color=blue]
    >| I am tryint to view a xml document in Internet Exploer as a ActiveX
    >| object using Javascript but it does not work. I only see the button
    >| but nothing happens when i click it. I am trying to view the
    >| 'firstChild' of the xml document.
    >|
    >| here is the code;
    >| ----------------------------------------------------------------
    >| <html>
    >| <head>
    >| <script language="javas cript">
    >| <!--
    >| function alert()
    >| {
    >| var xmldoc, meetingsNode, meetingNode;
    >| xmldoc = new ActiveXObject(" Microsoft.XMLDO M");
    >| xmldoc.load("me mbers.xml");
    >| document.write( "works so far");
    >| meetingsNode = xmldoc.document Element;
    >| document.write( "works so far");
    >| meetingNode = meetingsNode.fi rstChild;
    >| //does not process after this line
    >| document.writel n(meetingNode);
    >| }
    >| //-->
    >| </script>
    >|
    >| <title>Read Members.xml</title>
    >| </head>
    >| <body>
    >| <input type="button" name="submit" onclick="alert( )" />
    >| </body>
    >| </html>[/color]

    alert is a predefined javascript function. You might give your
    function another name i.e. xalert() and see what happens.
    ---------------------------------------------------------------
    jnorthau@yourpa ntsyahoo.com.au : Remove your pants to reply
    ---------------------------------------------------------------

    Comment

    • Martin Honnen

      #3
      Re: XML DOM in IE using Javascript



      Kenneth wrote:
      [color=blue]
      > I am tryint to view a xml document in Internet Exploer as a ActiveX
      > object using Javascript but it does not work. I only see the button
      > but nothing happens when i click it. I am trying to view the
      > 'firstChild' of the xml document.[/color]
      [color=blue]
      > var xmldoc, meetingsNode, meetingNode;
      > xmldoc = new ActiveXObject(" Microsoft.XMLDO M");
      > xmldoc.load("me mbers.xml");
      > document.write( "works so far");[/color]

      Loading happens asynchronously by default so you either need an
      onreadystatecha nge handler e.g.

      var xmlDocument = new ActiveXObject(' Microsoft.XMLDO M');
      xmlDocument.onr eadystatechange = function () {
      if (xmlDocument.re adyState == 4) {
      alert(xmlDocume nt.xml);
      }
      };
      xmlDocument.loa d('test20050423 01.xml');

      or you need to load synchronously

      var xmlDocument = new ActiveXObject(' Microsoft.XMLDO M');
      xmlDocument.asy nc = false;
      var wellFormed = xmlDocument.loa d('test20050423 01.xml');
      if (wellFormed) {
      alert(xmlDocume nt.xml);
      }

      but inside the browser synchronous loading blocks the user agent so that
      you would better use asynchronous loading as described above.


      --

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

      Comment

      Working...