W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2001

Re: d2d2xs: NMTOKEN vs. string

From: Jeni Tennison <jeni@jenitennison.com>
Date: Mon, 3 Dec 2001 22:32:22 +0000
Message-ID: <8214159229.20011203223222@jenitennison.com>
To: Stanley Guan <Stanley.Guan@oracle.com>
CC: Schema XML <xmlschema-dev@w3.org>, Joerg.Rieger@informatik.med.uni-giessen.de
Hi Stanley,

> Look at d2d2xs translated result.  Isn't it better to translate
>    <!ATTLIST patient
>                        pat_id   CDATA                  #REQUIRED
>                        kennung  (intern|extern|beides) #REQUIRED
>                        hausarzt IDREF                  #IMPLIED>
> to:
>
>       <xs:attribute name="kennung" use="required">
>         <xs:simpleType>
>           <xs:restriction base="xs:NMTOKEN">
>             <xs:enumeration value="intern" />
>             <xs:enumeration value="extern" />
>             <xs:enumeration value="beides" />
>           </xs:restriction>
>         </xs:simpleType>
>       </xs:attribute>
>
> instead of:
>
>       <xs:attribute name="kennung" use="required">
>         <xs:simpleType>
>           <xs:restriction base="xs:string">
>             <xs:enumeration value="intern" />
>             <xs:enumeration value="extern" />
>             <xs:enumeration value="beides" />
>           </xs:restriction>
>         </xs:simpleType>
>       </xs:attribute>
> because
>    Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'

Yes, using xs:NMTOKEN is better, although I think it could equally be
derived from xs:token - the only thing that xs:NMTOKEN gives you over
xs:string (aside from checking that the enumerated values are legal
NMTOKENs, and I assume you're assuming a valid DTD) is the
normalization of whitespace in attribute values, such that:

  kennung="   intern    "

would be a valid attribute value, whereas it isn't if it's derived
from xs:string (unless you explicitly set the whiteSpace facet to
collapse).

There's another tool at http://www.w3.org/2000/04/schema_hack/, which
has some useful examples of the conversions that it makes, although it
looks like it's based on an older version of XML Schema. I believe
that many XML editors have DTD to XML Schema converters built in (as
part of their support for XML Schema), try XML Spy for example.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/
Received on Monday, 3 December 2001 17:32:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:25 GMT