Using XML Schemas in Internet Explorer

Steven Holzner provides example code that puts the MSXML 4.0 package (which now supports full schemas) to work to load a new HTML page into Internet Explorer. The example uses JavaScript to load an XML schema in and use it to verify an XML document.

The XML support in Internet Explorer is built into the MSXML package. This
package was called the Microsoft XML Parser until version 4.0, when it was named
the Microsoft XML Core Services. Version 4.0 is the version that supports full
schemas, also called XML Schema Definition Language (XSD) schemas. Before
version 4.0, the MSXML package supported a smaller and different version of XML
schemas, which Microsoft calls XML-Data Reduced (XDR) schemas. You can see the
support for XML schemas by MSXML version in Table 5.1.

Table 5.1XML Schema Support by MSXML Version

Version

Support

MSXML

No support for schemas

MSXML 2.0

Support for XDR schemas

MSXML 2.6

Support for XDR schemas

MSXML 3.0

Support for XDR schemas

MSXML 4.0

Support for XSD and XDR schemas

If you're running Windows, how do you know what version of
MSXML you have? Take a look in the directory where Windows stores your system
dynamic link library (DLL) fileseither system or
system32 under the main Windows directory. If you see msxml3.dll and no
later version, you have MSXML 3.0. If you see msxml4.dll and no later version,
you have version 4.0.

Listing ch05_03.xml

If you take a close look at the XML schema here, you can probably figure out
what's going on: It's declaring an element named document. If
you look in the XML document, on the other hand, you can see that element in
use, along with a namespace that corresponds to this chapter,
<ch05:document>. Note, however, that the XML document also
contains an element named <ch05:data/>, which is not in
the schema. That's an error, and that's exactly what this example
reports, as you see in Figure 5.1. (Note that to run this example, ch05_01.html,
ch05_02.xsd, and ch05_03.xml should all be in the same directory.)

If you look closely at Listing ch05_01.html, you'll see that the code in
that example loads both the XML document and the XML schema. In fact, MSXML 4.0
lets you specify the location of the schema in the XML document, without having
to specify it in your code. You can indicate where the schema is with the
schemaLocation attribute in the XML document's root element; if
you use that attribute, you don't have to load the schema separately, as
you see in this new version of this example's HTML page:

When you load this new HTML page, ch05_04.html, into Internet Explorer,
you'll get the same results as you see in Figure 5.1 (to run this example,
ch05_02.xsd, ch05_04.html, and ch05_05.xml should all be in the same directory).
As you can see, Internet Explorer does indeed offer support for XML schemas.

Here's another exampleas discussed in Chapter 1, VB .NET uses XML
to transfer data. And it uses XML schema to validate that data. In fact, you can
take a look at such schema directly.

To do that, you need a data set from a database. To take a look at the XML
schema Visual Basic .NET uses for a particular dataset, use the Data | View
Dataset Schema menu item. This opens the data set's schema, in a Visual
Basic designer window, as you see in Figure 5.2.