spacer

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

home / experts / xml / column34

From DTDs to XML Schemas

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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