Tuesday, 25 March 2008

Validate XML in IE using JavaScript

Slightly off-topic, but as there don’t seem to be many good examples on the web of how to validate an XML document in IE using JavaScript, here’s a quick snippet. In the event of an XML error, an error message is displayed in the div.
<html xmlns="http://www.w3.org/1999/xhtml">
<title>XML Validator</title>

<script type="text/javascript">
function loadit()
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.validateOnParse = true;

if (xmlDoc.parseError != '0')
= xmlDoc.parseError.reason;


<body onload="loadit();">
<div id="error">

No comments: