spacer
Yehuda Shiran January 16, 2002
Loading XML from JavaScript
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

When creating and consuming Web services in Internet Explorer, you need to be familiar with XML and operations on XML. In particular, you need to know how to load an XML file from a JavaScript script, and how to manipulate the data loaded into the browser. The data read from an XML file is arranged in Internet Explorer's memory as an object, the DOMDocument object. This DOMDocument object has 35 properties, 25 methods, and 3 events. With this object, you can load XML files, navigate the document graph model, query nodes of the graph, etc. The first thing you need to do is to create an empty object. You do it with the ActiveXObject creator:

xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
You load an XML file with the load() method:

xmldoc.load("mydvd.xml");
The following script loads an XML file and prints its content to an alert box:

<SCRIPT LANGUAGE="JavaScript">
<!--
  var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
  xmldoc.load("mydvd.xml");
  alert(xmldoc.documentElement.xml);
// -->
</SCRIPT>
Try it in IE. You should get the XML file echoed back in an alert box.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint