[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Combining float/string to specify value/units

  • From: Eddie Robertsson <eddie@a...>
  • To: Steve.Rosenberry@E...
  • Date: Mon, 26 Mar 2001 18:07:54 +1000

xsd float
> As for the RE pattern, any ideas where I can find one already defined
> for a float number?  Despite my previous assertion of an application
> fully under my control, I'd like to make sure my patterns match the
> official XML Schema functionality as much as possible including the INF,
> NaN, and the exponential notations.
>
> Is the concept of using primitive datatypes in RE pattern matching
> encoding under consideration for future versions of XML Schema?  It
> seems inefficient not to be able to reuse all those wonderful built-in
> validation rules even if they may only be useful when restricting a
> string-based derived datatype.

This may be a long shot by I think this is a valid solution which could help you.
First define a type with all your different datatypes. E.g

<xsd:simpleType name="myTypes">
  <xsd:restriction base="xsd:string">
   <xsd:enumeration value="seconds"/>
   <xsd:enumeration value="msecs"/>
   <xsd:enumeration value="mins"/>
   <xsd:enumeration value="%"/>
   <xsd:enumeration value="knots"/>
   <!-- Add whatever else types you want -->
  </xsd:restriction>
 </xsd:simpleType>

Then create a union datatype that is a union between myTypes and xsd:float.

<xsd:simpleType name="myUnion">
  <xsd:union memberTypes="xsd:float myTypes"/>
 </xsd:simpleType>

If you create an element of this type you can have values of type "23.45", "12"
(any float), "msecs", "mins" etc. Now create a list type of your defined union
type.

 <xsd:simpleType name="myList">
  <xsd:list itemType="myUnion"/>
 </xsd:simpleType>

and finally restrict the list type to only contain 2 elements.

<xsd:simpleType name="my2List">
  <xsd:restriction base="myList">
   <xsd:length value="2"/>
  </xsd:restriction>
 </xsd:simpleType>

An element (or attribute) declared using my2List as type should have content like
"23.34 msecs", "12 mins" etc. The only problem is that "mins msecs", "mins 12",
"12.3 23" will also be valid but maybe that's ok?

Cheers,
/Eddie


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.