Solved

Issue with xsd:maxInclusive restriction for 'float' type

Posted on 2011-03-03
7
1,300 Views
Last Modified: 2012-05-11
Hi Experts,
My first question in the forum.

I've an XML file and an XSD to validate that. I've an element 'Duration' for which I've given a restriction of range. For eg [32.25, 128000]. I've defined the element as a simply type. Pls see  below,

 <xsd:simpleType>
      <xsd:restriction base="xsd:float">
           <xsd:minInclusive value="32.25"/>
            <xsd:maxInclusive value="128000"/>
      </xsd:restriction>
</xsd:simpleType>

But the problem is with values. If I give values like 128000.001, 128000.002, 12800.003 and validate against the schema 'no errors are reported!!'. But if I give a value 128000.004 or more I'm getting 'cvc-maxInclusive-valid' failure, which is what I need.
Note:
1) I'm using Oxygen 11.1 version.
2) The problem starts with values with 3 or more fractional digits.
Could u pls tell me wr the problem is?
0
Comment
Question by:vipinreyaroth
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 250 total points
ID: 35026078
The problem is in the precision of a xs:float
If this is important for you at that level of precision,
you should use xs:double
(I wonder actually why you would use xs:float after all)
0
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 35026101

I just had a look at the spec:
http://www.w3.org/TR/xmlschema-2/#rf-maxInclusive
There I can read:
The value of maxInclusive ·must· be in the ·value space· of the ·base type·.
And from the definition, i get:
value = anySimpleType

My guess would be that in your xsd 128000 is an integer and therefore the check is done in the integer value-space.
It's just a thing worth trying. Change your rule to this and see if it works:
<xsd:simpleType>
      <xsd:restriction base="xsd:float">
           <xsd:minInclusive value="32.25"/>
            <xsd:maxInclusive value="128000.0"/>
      </xsd:restriction>
</xsd:simpleType>

Open in new window

0
 

Author Comment

by:vipinreyaroth
ID: 35026365
Hi Gertone, ChristoferDutz thanks for your inputs.
1) @Gertone: Changing to 'xsd:double' works with the precision of 11 digits. But I've to keep the type as 'float' ( that's a requirement). So I think restricting the number of fractions (upto 2 digits for floats) using a pattern would help.
2) @ChristoferDutz: I tried, but it doesn't work. :(
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Assisted Solution

by:ChristoferDutz
ChristoferDutz earned 250 total points
ID: 35026405
Ahh ... dammit ... gertone is correct.
The problem is the number is internally represented as 32bit floating point number which means that it can store about 8 digits + their offset ... if you would set the upper limit to 128 instead of 128000 then you would get precision for 3 more digits in the fractional part. The problem is that when parsing the number as float the fractional part is simply stripped off and therefore cannot be used for comparison.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35026900
I was in the car for the past hour or so, so I missed your response.
You have conflicting requirements, you simply can't get the precision you want from an xs:float.

If you really want to use xs:float
and exclude some values at the high end,
use maxExclusive instead of maxInclusive (you will loose some valid values, but at least you get warned, being too strict is always better than not being strict enough)

Or use xs:double for the calculation in the schema and add a number type conversion after the validation in whatever technology you use to process the XML
At least your validation then happens on maximum precision
0
 

Author Comment

by:vipinreyaroth
ID: 35034313
Thanks Gertone. It'll do.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 35034357
welcome
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
RSS Feed Enclosure URL 1 164
Why does the Android Studio logcat show this error when the user presses the button? 2 49
XML Removal- Powershell 4 33
xml with php question 5 33
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question