[Home] [By Thread] [By Date] [Recent Entries]
Steve Rosenberry asks - > > Is it possible to derive an attribute type from a float primitive with > an appended string indicating the physical units associated with the > value? For example, I'd like to validate the following examples of > attribute values: > > 12.0 seconds > 1.11 msecs > 3.05 mins > > as a float followed by a restricted enumeration of allowable time > intervals. If by chance, there is a time type that already does this, > let me know, but specifying just time units isn't my only issue. I'm > interested in specifying any generic units i.e. db, knots, Hz, %'s (e.g. > 10%) etc... > But "12.0 seconds" isn't a float. It's a either a string or a type compounded from a float and a string. You can't derive a compound type from a primitive (I'm assuming you are thinking about xml-schema data types), since you can only restrict primitive types, not extend or compound them. If it's a string whose first part looks like a string representation of a float, by all means use a RE pattern. Otherwise, add a separate attribute to hold the units, then you can specify a floating point type independently of the units. Adding the attribute would be the better plan, most likely. Specifying units isn't necessarily as easy as it looks, since you might want to get into the handling of compound units (e.g., kg/m^2-sec), and this will potentially involve converting units to other forms. How much information one wants to pass to the application about the units and how they should be represented can be hard if full generality is needed. If course, I don't know if that applies to your case or not. Cheers, Tom P
|

Cart



