$Id: step6.sdoc 1.9 2000/11/01 13:45:32 murata Exp $
Among the features of DTD, we have not covered default values, entities, and notations. STEP 6 is concerned with them.
RELAX does not handle default values, entities, and notations. They are intentionally omitted from RELAX so that we can continue to use existing XML processors.
Suppose that RELAX introduced constructs for these features. For example, assume that RELAX had the
default attribute which provides the default value of an attribute. Existing XML processors will not examine RELAX modules when they parse XML documents. Thus, they will not use
default. The same thing applies to entities and notations: even if RELAX had constructs for declaring entities and notations, existing XML processors would not use them.
If we would like to introduce such features to RELAX, the only solution is to create RELAX-specific XML parsers. Those users who create and verify XML documents against RELAX grammars would certainly have to use such RELAX-specific XML parsers. Furthermore, those users who receive such XML documents would have to switch to RELAX-specific XML parsers. In our opinion, this is not very realistic.
Then, are we unable to use default values, entities, and notations? No, we can use these features if we use DTD and RELAX together.
The following is an XML document containing a DTD.
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE person [ <!ATTLIST person bloodType CDATA "A"> ]> <person/>
This document is verified against a RELAX module as below:
<module moduleVersion="1.0" relaxCoreVersion="1.0" xmlns="http://www.xml.gr.jp/xmlns/relaxCore"> <interface> <export label="person"/> </interface> <elementRule role="person"> <empty/> </elementRule> <tag name="person"> <attribute name="bloodType"> <enumeration value="O"/> <enumeration value="A"/> <enumeration value="B"/> <enumeration value="AB"/> </attribute> </tag> </module>
In this example, the DTD specifies the default value "A". XML processors do use this default. We can verify this XML document against the RELAX module without any problems. Verification is done as if "A" was specified as the attribute value.
Similarly, entities and notations can be described in DTD. First, we show an example of parsed entities.
<?xml version="1.0"?> <!DOCTYPE doc [ <!ENTITY foo "This is a pen"> ]> <doc> <para>&foo;</para> </doc>
This document is legitimate against the RELAX module as below:
<module moduleVersion="1.0" relaxCoreVersion="1.0" xmlns="http://www.xml.gr.jp/xmlns/relaxCore"> <interface> <export label="doc"/> </interface> <elementRule role="doc"> <ref label="para" occurs="*"/> </elementRule> <elementRule role="para" type="string"/> <tag name="doc"/> <tag name="para"/> </module>
Next, we show an example of unparsed entities and notations.
<?xml version="1.0"?> <!DOCTYPE doc [ <!NOTATION eps PUBLIC "-//ISBN 0-7923-9432-1::Graphic Notation//NOTATION Adobe Systems Encapsulated Postscript//EN"> <!ENTITY logo_eps SYSTEM "logo.eps" NDATA eps> <!ELEMENT doc EMPTY> <!ATTLIST doc logo ENTITY #IMPLIED> ]> <doc logo="logo_eps"/>
This document is legitimate against the following RELAX module.
<module moduleVersion="1.0" relaxCoreVersion="1.0" xmlns="http://www.xml.gr.jp/xmlns/relaxCore"> <interface> <export label="doc"/> </interface> <elementRule role="doc" type="emptyString"/> <tag name="doc"> <attribute name="logo" type="ENTITY"/> </tag> </module>
As we have seen in the previous section, we can use default values, entities, and notations by using DTD and RELAX together. Their use is not recommended, however.
Default values can be mimicked by application programs. We only have to hardcode "default values" in application programs and use them when attributes are absent. We can also write XSLT scripts so as to embed "default values" when attributes are absent.
Use links (especially, XLink) rather than external parsed entities or external unparsed entities. Links are much more appropriate for the WWW.
Internal parsed entities can be used without any problems, however. Some text data such as "<" can be best represented by internal parsed entities (e.g., <).
Unfortunately, default values, entities, and notations in DTD are not always processed as expected by casual users. This is because some XML processors do not fetch external DTD subsets or external parameter entities. However, all examples in this STEP use internal DTD subsets and thus are free from such unexpected results.
STEPs 1 thru 6 provide more than enough features for the migration from DTD to RELAX. As long as we use these features only, we can convert RELAX to DTD and vice versa without loss of information except for datatypes and facets. In the future, conversion between XML Schema should be possible. Enjoy and RELAX!