topical media & game development

talk show tell print

professional-javascript-15-IEXmlDomExample4.htm / htm



  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  
  <html>
      <head>
          <title>IE XML DOM Example</title>
          <script type="text/javascript">
          function createXMLDOM() {
          
              var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0",
                                   "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument",
                                   "Microsoft.XmlDom"];
                                   
              for (var i=0; i < arrSignatures.length; i++) {
                  try {
                  
                      var oXmlDom = new ActiveXObject(arrSignatures[i]);
                      
                      return oXmlDom;
                  
                  } catch (oError) {
                      //ignore
                  }
              }              
              
              throw new Error("MSXML not installed on your system.");           
          }               
          </script>        
      </head>
      <body>
          <p>This example loads an XML file with errors and displays an error dialog.</p>
          <script type="text/javascript">
              var oXmlDom = createXMLDOM();
              
              oXmlDom.async = false;
              oXmlDom.load("errors.xml");
              
              if (oXmlDom.parseError != 0) {
                  var oError = oXmlDom.parseError;
              
                  alert("An error occurred:\nError Code: "
                        + oError.errorCode + "\n"
                        + "Line: " + oError.line + "\n"
                        + "Line Pos: " + oError.linepos + "\n"
                        + "Reason: " + oError.reason);
                        
              }
          </script>
   
   
      </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.