January 16, 2002 - Loading XML from JavaScript
January 16, 2002 Loading XML from JavaScript Tips: January 2002
Yehuda Shiran, Ph.D.
|
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.