Loading XML from JavaScript

SearchDomino.com member Chandra Teja explains how to load XML from JavaScript and manipulate the data in Internet Explorer using the DOMDocument object.

When creating and consuming Web services in Internet Explorer, you need to be familiar with operations in Extensible Markup Language (XML). Specifically, you have to know how to load an XML file from JavaScript and manipulate the data loaded into the Web browser.

The data read from an XML file is arranged in Internet Explorer's memory as an object called DOMDocument. The DOMDocument object has 35 properties, 25 methods, and three events.

With this object, you can load XML files, navigate the document graph model and query nodes of the graph. The first thing you need to do is create an empty object, which you can accomplish with the ActiveXObject creator:

xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");

Now you can load the XML file with the load() method:


The following script loads an XML file and prints its content to an alert box. Try it in Internet Explorer. You should get the XML file echoed back in an alert box.

  var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
// -->

Do you have comments on this tip? Let us know.

Related information from SearchDomino.com:

  • Learning Guide: Extensible Markup Language
  • Learning Guide: JavaScript
  • Tip: Transferring Domino information to JavaScript
  • Reference Center: JavaScript tips and resources
  • Reference Center: XML/Web services tips and resources

    This tip was submitted to the SearchDomino.com tip library by member Chandra Teja. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.

  • Dig Deeper on JavaScript for Lotus Notes Domino

    • Favorite iSeries cheat sheets

      Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...