spacer

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

home / experts / xml / column34

From DTDs to XML Schemas

Web Design Manager
IT Search
US-NE-Kimball

Justtechjobs.com Post A Job | Post A Resume
Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source

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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

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