spacer
Yehuda Shiran February 25, 2002
Validating DOMDocument Upon Request
Tips: February 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Since you can add and modify nodes to the DOMDocument tree, there must be a way to validate the DOMDocument upon request, and not only upon loading. You can do this in later versions of Internet Explorer with the validate() method. Here is code that loads an XML file, adds an attribute to the root node, and validates the new DOMDocument:

function validateXML() {
  var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
  xmlDoc.async = false;
  xmlDoc.load("mydvd7.xml");
  xmlDoc.documentElement.setAttribute("foo", "bar");
  var err = xmlDoc.validate();
  if (err.errorCode == 0) {
    alert("Document is valid");
  } else {
      alert("Validation error:" + err.reason);
	}
}
Notice the err error object that holds very useful information. For example, it pinpoints the fact that the new attribute "foo" is not defined in the DTD file and hence is illegal. Try it.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends