Volume 3, Issue 5 - September/October 2003
 
   
 

In this monthly column, an industry expert will answer common questions about VoiceXML and related technologies. Readers are encouraged to submit questions about VoiceXML, including development, voice-user interface design, and speech technology in general, or how VoiceXML is being used commercially in the marketplace. If you have a question about VoiceXML, e-mail it to and be sure to read future issues of VoiceXML Review for the answer.

Continued from previous page...


Q: What about schema validation?


A: DTDs are useful for validating basic parent/child relationships between elements and for performing some basic checks on attribute values.
Beyond that, however, they are extremely limited in the constraints that they can specify on an XML document.

Two important advantages that XML schemas offer over DTDs include:

1) XML Schemas allow you to prescribe different element constraints based on the element's context. For example, in VoiceXML, A <filled> element within an input item cannot specify a mode attribute or a namelist attribute (http://www.w3.org/TR/voicexml20/#dml2.4).
While it is possible to specify this constraint using an XML schema, it is not possible to do so using a DTD.

2) XML Schemas provide rich data type support. For example, several attributes (e.g. timeout) in VoiceXML 2.0 require a "Time Designation"
(http://www.w3.org/TR/voicexml20/#dml6.5). XML Schemas allow you to express that restriction using a regular expression.

DTDs are limited to simple enumerations on attribute values.

In short, the range of errors you can detect by validating your VoiceXML documents against an XML Schema is superior to those that you can detect using a DTD.

So, why doesn't everyone use XML Schemas? Compared with DTDs which were adopted from SGML, XML schema is a fairly recent technology,
and the XML toolsmiths are still catching up.

To associate an XML document with a specific schema, you'll need to add a few attributes to your VoiceXML document.

The following VoiceXML document binds the prefix "xsi" to the XMLSchema-instance namespace, and then uses the schemaLocation attribute in the XMLSchema-instance namespace to reference the official VoiceXML 2.0 schema as specified in Appendix O of the VoiceXML 2.0 specification (http://www.w3.org/TR/voicexml20/#dmlASchema):

<vxml version="2.0"
   xmlns="http://www.w3.org/2001/vxml"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.w3.org/2001/vxml
      http://www.w3.org/TR/voicexml20/vxml.xsd"
>
   <form>
      <block>
         <prompt>
            <prosody volume="110">Hello, world.</prosody>
         </prompt>
      </block>
   </form>
</vxml>

If you want to examine the schema and all its dependencies, you can download the following .zip from the W3C site:
http://www.w3.org/TR/voicexml20/vxml-schema.zip

For more information about XML schema, see the XML schema specification on the W3C site. The specification is divided into two parts:

XML Schema Part 1: Structures (http://www.w3.org/TR/xmlschema-1/)
XML Schema Part 2: Datatypes (http://www.w3.org/TR/xmlschema-2/)

To validate the above document against the VoiceXML 2.0 schema, one of your best bets in open source tools, as of this writing, is Xerces from the Apache Software Foundation (http://xml.apache.org/). Language bindings are available for C++, Perl, and Java 2.

The Java download includes an example, Counter.java, in the samples\sax\ directory that performs schema validation using the Xerces SAX parser (org.apache.xerces.parsers.SAXParser). To use this sample, make sure you have the path to both xercesImpl.jar and xercesSamples.jar in your classpath.

The following command-line enables full validation using XML schemas:

   java sax.Counter -v -s -f hello.vxml

The resulting output follows:

   [ERROR] hello.xml:15:32: cvc-datatype-valid.1.2.2: '110' is not a valid value of list type 'volume.datatype'.
   [ERROR] hello.xml:15:32: cvc-attribute.3: The value '110' of attribute 'volume' on element 'prosody' is not valid with respect to its type.

Modify the VoiceXML above document by removing the schema-related attributes and by adding a DOCTYPE declaration that references the VoiceXML 2.0 DTD.

Use a DTD validating XML parser to load the document, and observe that, due to the limitations of DTDs, it doesn't report any errors.

Note that, while XML validation is an important step, it won't catch run-time errors.

The following example attempts to reference a variable that hasn't been declared.

An XML validation tool won't catch that. To detect such an error, you'll have to execute the VoiceXML document using a real VoiceXML interpreter and then check the resulting call log.

<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<form>
   <block>
      Hello, <value expr="user"/>
   </block>
</form>
</vxml>

For a list of VoiceXML development tools and environments that will allow you to execute your VoiceXML applications, see the VoiceXML Forum's "Development Tools" resource page:

http://www.voicexml.org/resources/devtools.asp.

As you work through this list, you'll probably notice that a number of the development environments, Tellme Studio (http://studio.tellme.com/) for example, include a syntax checker. At the heart of these tools is an XML parser that performs validation against some version of the VoiceXML DTD or schema.

One of the advantages to using the syntax checker provided with the development environment, is that each is specifically geared toward the limitations and extended features of the target VoiceXML platform.




back to the top

Copyright © 2001-2002 VoiceXML Forum. All rights reserved.
The VoiceXML Forum is a program of the
IEEE Industry Standards and Technology Organization (IEEE-ISTO).