spacer

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

home / experts / xml / column35

Converting DTDs to XML Schemas

Sr. Web Developer
mediabistro.com
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?


Manual work

We immediately run into a bug here: Both the channel and item definitions contain elements of name ? and +, rather than having these symbols translated into minOccurs and maxOccurs constraints. This is also provoked by the strange DTD definitions of these elements, which should rather read:

<!ELEMENT channel (title, description, link, language, item+, 
 rating?, image?, textinput?, copyright?, pubDate?, lastBuildDate?, 
 docs?, managingEditor?, webMaster?, skipHours?, skipDays?)>

This stricter element definition would be more accurately converted into:

<element name="channel">
 <element ref="title" minOccurs="1" maxOccurs="1"/>
 <element ref="description" minOccurs="1" maxOccurs="1"/>
 <element ref="link" minOccurs="1" maxOccurs="1"/>
 <element ref="language" minOccurs="1" maxOccurs="1"/>
 <element ref="item" minOccurs="1"/>
 <element ref="rating" minOccurs="0" max="1"/>
 <element ref="image" minOccurs="0" max="1"/>
 <element ref="textinput" minOccurs="0" max="1"/>
 <element ref="copyright" minOccurs="0" max="1"/>
 <element ref="pubDate" minOccurs="0" max="1"/>
 <element ref="lastBuildDate" minOccurs="0" max="1"/>
 <element ref="docs" minOccurs="0" max="1"/>
 <element ref="managingEditor" minOccurs="0" max="1"/>
 <element ref="webMaster" minOccurs="0" max="1"/>
 <element ref="skipHours" minOccurs="0" max="1"/>
 <element ref="skipDays" minOccurs="0" max="1"/>
</element>

Increased Precision

In the last article we emphasized that XML Schema allows for increased precision for specifying constraints on elements and attributes. The RSS version atribute needs to be "0.91". In XML Schema we can express this with:

<element name="rss">
 <complexType content="elementOnly">
  <attribute name="version" type="string" use="fixed" value="0.91"/>
 </complexType>
</element>

One of the conventions on Netscape's former RSS syndication system was that a channel could only have up to 15 elements.

<element ref="item" minOccurs="1" maxOccurs="15"/>
More constraints on other elements of the RSS definition can be enforced in similar ways.

Conclusion

The conversion tool cannot work magic if the underlying DTD is already fairly lax. The RSS 0.91 definition is not very restrictive so a lot of manual work is required, including working around bugs. Nevertheless on the W3C site there are successful conversions of P3P, SMIL, XHTML, and MathML, so an automatic conversion seems feasible for better-behaved DTDs.

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/column35/3.html
Created: Jul 18, 2001
Revised: Jul 18, 2001