Basic XML and javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • littlecoder
    New Member
    • Oct 2008
    • 3

    Basic XML and javascript

    Hello ,
    I am very new to XML and javascript . I want to display data from a XML file using javascript . My XML file is named as first.xml . My html file is as below :

    <html>
    <body>
    <script langauge = "text/javascript">
    var xmlDoc = new ActiveXObject(" Microsoft.XMLDO M");
    xmlDoc.load('fi rst.xml');
    xmlObj=xmlDoc.d ocumentElement;
    alert(xmlObj.xm l);
    </script>
    </body>
    </html>

    But this does not work ? Can anyone help me ?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    first:
    Code:
    <script type="text/javascript">
    second:
    like in ajax use a try-catch construct because not everyone will use IE (and FF doesn't support ActiveXObject)
    third:
    are there any error messages?

    tip of the day: developer.mozil la.org (very comprehensive references)

    regards

    Comment

    • jkmyoung
      Recognized Expert Top Contributor
      • Mar 2006
      • 2057

      #3
      You need to check if that object is supported. Eg check
      if (window.ActiveX Object)
      if not, check if (document.imple mentation
      && document.implem entation.create Document)

      A related page is found here:
      Sorry! We can't seem to find the resource you're looking for

      Comment

      Working...