On Thu, Aug 25, 2005 at 10:27:39AM -0700, Jacob Danner wrote:
> What happens when you use something like xsd:fractionDigits in your 
> restriction. It may be easier than using a regex pattern.
> 
> http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits

I think fractionDigits restriction is not available for double.

> Please let us know what happens,

The problem I had was more of a "wrong way of thinking" problem. I agree
that there is no sense in using the pattern to validate the number of
fractiondigits. The reason I tried the pattern was that the decimal
fractiondigits restriction did not work (in the beginning). And the
reason for this was that I tried to create BigDecimals using the
constructor that takes a double parameter. 

double amountOfHours = 1.2;
someElement.setHours(new BigDecimal(amountOfHours));

This way I got lots of decimals and the validation failed. Once I tried
the constructor that takes a String as a parameter the validation works.
It looks a bit ugly in the code when I have to write

double amountOfHours = 1.2;
someElement.setHours(new BigDecimal(Double.toString(amountOfHours)));

but I guess that's the only solution. Now I am able to use the decimal
and the fractiondigits restriction.

Let me know if there is some smarter solutions.

-Niklas

> -Jacobd
> 
> -----Original Message-----
> From: Niklas Koponen [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, August 25, 2005 6:47 AM
> To: [email protected]
> Subject: Writing double from java-code to XML
> 
> Hi!
> 
> I am using xmlbeans-2.0.0.
> 
> I have the following problem. I have defined a type in my schema which
> restricts that a double should have two decimals.
> 
> <xsd:simpleType name="kilometersType">
>       <xsd:restriction base="xsd:double">
>               <xsd:pattern value="\d{0,4}[\.]\d{2}"/>
>       </xsd:restriction>
> </xsd:simpleType>
> 
> I have generated the java files using scomp.
> 
> Now I set the value of the element that is of type workinghoursType in
> java code.
> 
> expenses.setKilometers(1.20);
> 
> When I try to validate the element using validate() the validation
> fails. This is because the element that is supposed to contain two
> decimals contains only one decimal.
> 
> When I write the object to XML (without validating) it writes the data
> there as 1.20.
> 
> The writing works as expected but the validating fails. This is
> problematic because I need to validate before writing to file.
> 
> Am I missing something important. I have skimmed through the javadoc and
> the mailinglist archive through eyebrowse but haven't found an answer.
> 
> Is this a bug in xmlbeans?
> 
> -Niklas
> -- 
> Niklas Koponen, [EMAIL PROTECTED], +358 40 757 1459
> Fifth ELement Oy / GISnet Solutions Oy
> Tietäjäntie 2, FIN-02130 Espoo
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

-- 
Niklas Koponen, [EMAIL PROTECTED], +358 40 757 1459
Fifth ELement Oy / GISnet Solutions Oy
Tietäjäntie 2, FIN-02130 Espoo


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to