OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] "Datatypes" for DTDs

[ Lists Home | Date Index | Thread Index ]

At 10/1/02 07:37 PM, Arjun Ray wrote:
>"Wayne Steele" <xmlmaster@hotmail.com> wrote:
>|From: Sam Hunting <shunting@etopicality.com>
>|> [Wayne Steele <xmlmaster@hotmail.com>]
>
>|>> 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





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS