a developer's notes – a semi-technical web development BLOG

September 5, 2011

Loading XML from JavaScript

Filed under: General Tips — Duy Nguyen @ 1:25 pm
Tags: , , , ,

This was taken from: http://www.webreference.com/js/tips/020116.html

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:

  var xmldoc=new ActiveXObject("MSXML2.DOMDocument.3.0");
  xmldoc.load("mydvd.xml");
  alert(xmldoc.documentElement.xml);

You can also use XPath to choose a node:

xmlDoc.selectSingleNode("//NODE[@id=\"567\"]")
Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: