spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column34

From DTDs to XML Schemas

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


Translation of elements and attributes

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>

Manual work

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:

Conclusion

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.

http://www.internet.com

Produced by Michael Claßen

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

URL: http://www.webreference.com/xml/column34/2.html
Created: Jun 28, 2001
Revised: Jun 28, 2001