| home / experts / xml / column34 |
|
|
The translation works as follows:
| DTD | XML Schema |
|---|---|
<!ELEMENT ROOT (A,B) > |
<element name="ROOT"> <complexType content="elementOnly"> <element ref="t:A"> <element ref="t:B"> </complexType> <element> |
<!ELEMENT ROOT (A|B) > |
<element name="ROOT"> <complexType content="elementOnly"> <choice> <element ref="t:A"> <element ref="t:B"> </choice> </complexType> <element> |
<!ELEMENT ROOT (A|(B,C)) > |
<element name="ROOT">
<complexType content="elementOnly">
<choice>
<element ref="t:A">
<sequence>
<element ref="t:B">
<element ref="t:C">
</sequence>
</choice>
</complexType>
<element>
|
<!ELEMENT ROOT (A?,B+,C*) > |
<element name="ROOT"> <complexType content="elementOnly"> <element ref="t:A" minOccurs="0"> <element ref="t:B" maxOccurs="unbounded"> <element ref="t:C" minOccurs="0" maxOccurs="unbounded"> </complexType> <element> |
Encoding of attributes works like so:
| DTD | XML Schema |
|---|---|
<!ATTLIST ROOT
a CDATA #REQUIRED>
|
<element name="ROOT"> <complexType content="elementOnly"> <attribute name="a" type="string" use="required"/> </complexType> <element> |
<!ATTLIST ROOT
a CDATA #IMPLIED>
|
<element name="ROOT"> <complexType content="elementOnly"> <attribute name="a" type="string" use="optional"/> </complexType> <element> |
<!ATTLIST ROOT
a (x|y|z) #REQUIRED;>
|
<element name="ROOT">
<complexType content="elementOnly">
<attribute name="a">
<simpleType base="string">
<enumeration value="x"/>
<enumeration value="y"/>
<enumeration value="z"/>
</simpleType>
</attribute>
</complexType>
<element>
|
<!ATTLIST ROOT
a CDATA #FIXED "x">
|
<element name="ROOT"> <complexType content="elementOnly"> <attribute name="a" type="string" use="fixed" value="x"/> </complexType> <element> |
Some manual work after the conversion is necessary to take advantage of the improved expressiveness of XML Schema. The tool can of course only translate the information present in a DTD into the new syntax, everything else needs to be added afterwards:
Converting DTDs to XML Schema Definitions allows for improved XML document processing in software. The conversion tool introduced here takes on the tedious task of translating every DTD definition into its equivalent XML Schema form, but the higher expressiveness only comes into play after manually updating the generated schema definition.
Produced by Michael Claßen
URL: http://www.webreference.com/xml/column34/2.html
Created: Jun 28, 2001
Revised: Jun 28, 2001