Testing your DTD XML Schema Validation [con't]
Creating the XML Parser Object
There are several versions of XML parsers available, version six being the
most recent. The original and most basic one is the
library. It points to the msxml version 2 dll. To create it, use the following
An equivalent way of referencing version 2 of the msxml
library is to use the
The following lines will both invoke version 3:
Note that MSXML can exist with many different versions
on a single computer. Some upgrades are overwrites and some are side-by-side.
The following page on the Microsoft website
explains the differences between the various msxml libraries. When
in doubt as to which version you want to use, stick with
Figure 1 shows an example of an XML file that passed the validation test:
Figure 2 shows an XML document which did not pass because the
case_list element did not
have any children. According to our DTD spec, it must contain at least one:
Validating multiple XML Documents in a Batch Process
When validating a small XML document as we are here, it isn't too time intensive to validate each test scenario using the validateCaseSummary.html file. However, it can become a burdensome task when testing larger documents. For those, I recommend using a batch process. The Windows operating systems can execute scripts using the Windows Script Host (WSH). WSH provides an environment for scripts to run; it invokes the appropriate script engine and provides a set of services and objects for the script to work with. These scripts may be run in either GUI mode (WScript.exe) or command line mode (CScript.exe), offering flexibility to the user for interactive or non-interactive scripts. Windows scripting is used for a variety of purposes, including logon scripts, administration and general automation.
This script makes use of three other objects, in addition to the
Wscript.Shell is used to set the working directory, which saves us from
constantly including the full path to directories and folders. The
property holds the full path to our script. From it, we can obtain the path
without the file name, using the
InStrRev() function. It returns the character
position of the last backslash (\) in the path.
Scripting.FileSystemObject serves multiple purposes, including:
- obtaining a reference to the
- creating the results file (line 20)
- returning the extension of each file in the directory (line 23)
Shell.Application object launches the associated program to view
the results text file.
Unlike the validateCaseSummary.html file, which displays the results for one XML document in the browser, the batch process outputs a report for all the XML files in the directory:
Rob Gravelle combined his love of programming and music to become a software guru and accomplished guitar player. He created systems that are used by Canada Border Services, CSIS and other Intelligence-related organizations. As a software consultant, Rob has developed Web applications for many businesses and recently created a MooTools version of PHPFreechat for ViziMetrics. Musically, Rob recently embarked on a solo music career, after playing with Ivory Knight since 2000. That band was rated as one Canada's top bands by Brave Words magazine (issue #92) and released two CDs. Rob's latest, entitled KNIGHTFALL, was a collaboration between himself, the former Ivory Knight vocalist, and legendary guitarist/producer, Jeff Waters of Annihilator fame. Rob is available for short-term software projects and recording session work. to inquire, but note that, due to the volume of emails received, he cannot respond to every email. Potential jobs and praise receive highest priority!
Original: June 3, 2009