XSD: restrict attribute to xs:float or ""

Viewed 6411

I'm trying to define an element type in XSD, for which i want an optional attribute, which if present can either contain a float, or be empty (but still present).

i.e:

<xs:element name="MyElement">
    <xs:complexType>
        <xs:attribute name="optionalFloatAttribute" type="xs:float" use="optional"/>
    </xs:complexType>
</xs:element>

Needs "fixing" to allow all of the following xml:-

<MyElement/>
 or
 <MyElement optionalFloatAttribute=""/>
 or
 <MyElement optionalFloatAttribute="3.14159"/>

The only way I can see of doing this is to change type to xs:string, and use xs:restriction with a regular expression. But this doesn't seem very ideal to me. Is there a better way?

And I have to be able to support these variations of the xml - the program and existing xml is legacy, and I am trying to back-create a schema to match the myriad variations I see in what we have to regard as valid xml.

3 Answers
Related