[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: "Datatypes" for DTDs


journal of markup languages
At 10/1/02 07:37 PM, Arjun Ray wrote:
>"Wayne Steele" <xmlmaster@h...> wrote:
>|From: Sam Hunting <shunting@e...>
>|> [Wayne Steele <xmlmaster@h...>]
>
>|>> One trick that people have used for ages to indicate data types in  
>|>> DTDs is through parameter entities. [...] This works great for human 
>|>> documentation, but is not especially machine processable.
>
>Right.  Mnemonic PE names have always been a form of handwaving. :-)

All right, here's my trick for datatypes in DTDs, and I think it uses PEs better than others that I've seen. This would have had more exposure if the late great "Journal of Markup Languages" had published for one more issue. (Then again, although my article on this was accepted there, it was rejected as an XML 2002 Baltimore submission.)

To summarize: for simple element types, instead of the e-dtype attribute used by DT4DTD, use a #FIXED xsi:type attribute described
in section 2.6.1 (http://www.w3.org/TR/xmlschema-1/#xsi_type) of XML Schema Part 1, which is used more widely. 

For attribute typing, I do have parameter entity trick, but I thought it was better than the DT4DTD one. Imagine two files of parameter entity declarations like this:

  <!ENTITY % DTDDecls       SYSTEM "DTDDecls.dtd">
  <!ENTITY % SchemaPt2Decls SYSTEM "SchemaPt2Decls.dtd">

DTDDecls maps type names to XML 1.0 attribute types, like this, 

  <!ENTITY % string             "CDATA">
  <!ENTITY % boolean            "(true|false)">
  <!ENTITY % decimal            "NMTOKEN">
  <!ENTITY % float              "NMTOKEN">
  <!ENTITY % double             "NMTOKEN">
  <!-- etc. -->

and SchemaPt2Decls maps the same ones to Schema Part 2 types, like this:

  <!ENTITY % string             "xsd:string">
  <!ENTITY % boolean            "xsd:boolean">
  <!ENTITY % decimal            "xsd:decimal">
  <!ENTITY % float              "xsd:float">
  <!ENTITY % double             "xsd:double">
  <!-- etc. -->

(Of course, you could map them to any set of types you liked.)

Declare your attribute types using these parameter entities, 

  <!ATTLIST order    itemNum  %string;  #REQUIRED
                     price    %float;   #IMPLIED
                     quantity %integer; #IMPLIED
                     shipped  %boolean; #IMPLIED
  >                   

and reference the %DTDDecls; set for plain old XML 1.0 work. 

If you reference the %SchemaPt2Decls; parameter entity instead, the DTD can be converted to a schema with all typing information intact if you take the dtd2xsd.pl script from http://www.mathling.com/xmlschema, change one line of it, and add two more. 

Then, you can name types all you want in your DTDs and preserve the typing information when you do convert the DTDs to schemas. 

Bob DuCharme          www.snee.com/bob           <bob@  
snee.com>  "The elements be kind to thee, and make thy
spirits all of comfort!" Anthony and Cleopatra, III ii


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.