Re: <time> values in HTML5

Original Message From: "C. M. Sperberg-McQueen"
> It would be an interesting exercise to specify both an extension type
> with its own value space and lexical mapping, and a type usable in
> processors which don't support the extension type.   I think the XML
> Schema WG might be interested in collaborating on a document with
> such a specification; if the WG isn't interested as a group, I expect that
> some individuals in the WG may be interested.  From the XML Schema
> WG's point of view, such a document would probably be interesting and
> worth working on even if some of those interested in HTML5 and RDF
> were to decide they don't care to use it.

In case you're looking for an 'automated' solution I came up with the 
following syntax.  My concern with Jeni's approach was that it was very good 
with parsing an XML value into it's component parts, and converting from one 
form to another, but I couldn't readily see how it worked for converting 
something like a Java object (e.g. class Date{ private int year; private int 
month;...};)  to an XML value.  But then maybe that's only a niche problem.

In the two examples below I've used the 'format' attribute to describe how a 
value should be formatted for output (based on C and Java format specifiers) 
and used the 'condition' attribute to indicate when a particular block of 
data should be output.

I've described it as an extension that can be plugged into an XSD.

HTH!

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsdt="http://www.w3.org/2001/XMLSchemaDataTypes">
    <xs:simpleType name="date">
        <xs:restriction base="xs:string">
            <xsdt:compoundType>
                <xsdt:sequence>
                    <xsdt:value name='year' type='xs:int' format='04d'/>
                    <xsdt:literal value='-'/>
                    <xsdt:value name='month' format='02d'>
                        <xs:simpleType>
                            <xs:restriction base='xs:int'>
                                <xs:minInclusive value='1'/>
                                <xs:maxInclusive value='12'/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xsdt:value>
                    <xsdt:literal value='-'/>
                    <xsdt:value name='day' format='02d'>
                        <xs:simpleType>
                            <xs:restriction base='xs:int'>
                                <xs:minInclusive value='1'/>
                                <xs:maxInclusive value='31'/>
                            </xs:restriction>
                        </xs:simpleType>
                    </xsdt:value>
                <xsdt:sequence>
            </xsdt:compoundType>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsdt="http://www.w3.org/2001/XMLSchemaDataTypes">
    <xs:simpleType name="duration">
        <xs:restriction base="xs:string">
            <xsdt:compoundType name='duration'>
                <xsdt:sequence>
                    <xsdt:literal name='isNeg' value='-' minOccurs='0' 
condition='isNeg'/>
                    <xsdt:literal value='P'/>
                    <xsdt:sequence minOccurs='0'>
                        <xsdt:value name='years' type='xs:unsignedInt'/>
                        <xsdt:literal value='Y'/>
                    </xsdt:sequence>
                    <xsdt:sequence minOccurs='0'>
                        <xsdt:value name='months' type='xs:unsignedInt'/>
                        <xsdt:literal value='M'/>
                    </xsdt:sequence>
                    <xsdt:sequence minOccurs='0'>
                        <xsdt:value name='days' type='xs:unsignedInt'/>
                        <xsdt:literal value='D'/>
                    </xsdt:sequence>
                    <xsdt:sequence minOccurs='0' condition='hours>0 || 
minutes>0 || seconds>0'>
                        <xsdt:literal value='T'/>
                        <xsdt:sequence minOccurs='0' condition='hours>0'>
                            <xsdt:value name='hours' type='xs:unsignedInt'/>
                            <xsdt:literal value='H'/>
                        </xsdt:sequence>
                        <xsdt:sequence minOccurs='0' condition='minutes>0'>
                            <xsdt:value name='minutes' 
type='xs:unsignedInt'/>
                            <xsdt:literal value='M'/>
                        </xsdt:sequence>
                        <xsdt:sequence minOccurs='0' condition='seconds>0'>
                            <xsdt:value name='seconds' 
type='unsignedFloat'/>
                            <xsdt:literal value='M'/>
                        </xsdt:sequence>
                    </xsdt:sequence>
                </xsdt:sequence>
            </xsdt:compoundType>
        </xs:restriction>
    </xs:simpleType>
</xs:schema>

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info

Received on Friday, 2 December 2011 16:55:50 UTC