[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    [jira] Commented: (XMLBEANS-175) Validation of decimal in exponential representation fails
From:       "Johannes Stamminger (JIRA)" <xmlbeans-dev () xml ! apache ! org>
Date:       2005-07-25 12:40:48
Message-ID: 1758879659.1122295248265.JavaMail.jira () ajax ! apache ! org
[Download RAW message or body]

    [ http://issues.apache.org/jira/browse/XMLBEANS-175?page=comments#action_12316660 \
] 

Johannes Stamminger commented on XMLBEANS-175:
----------------------------------------------

My documentation was not correct (and the other parser neighther), but I still \
believe xmlbeans should be changed concerning handling of decimals:

according http://www.w3.org/TR/xmlschema-2/#decimal exponential representation is not \
allowed. Though java.lang.BigDecimal does.

In my app I build up the document in memory using the xmlbeans created API. There the \
schema-decimal is mapped to java BigDecimals. When setting such value and having \
exponential representation, this string is complained about when validating the \
document (and is written to output on saving).

IMHO xmlbeans should not use the BigDecimal#toString() but BigDecimal#toPlainString() \
(1E1 becomes 10 this way) when validating/saving/... .

Workaround is to do so "from outside" at the moment, here some junit test for the \
attached schema/xmlbeans generated library that currently fails:

    public void testDecimal() {
        final TestExponentDocument.TestExponent exponent = \
TestExponentDocument.TestExponent.Factory.newInstance();  exponent.setDecimal(new \
BigDecimal("1E1"));  final ArrayList errors = new ArrayList();
        final XmlOptions validationOptions = new XmlOptions();
        validationOptions.setErrorListener(errors);
        exponent.validate(validationOptions);
        assertEquals(0, errors.size()); // fails, IMHO should not!

        // workaround
        exponent.setDecimal(new BigDecimal(new BigDecimal("1E1").toPlainString()));
        errors.removeAll(errors);
        exponent.validate(validationOptions);
        assertEquals(0, errors.size());
    }


One additional note on the error handling here: it is not very helpfull only to \
report the wrong char. Message should contain at least the complete number String.

> Validation of decimal in exponential representation fails
> ---------------------------------------------------------
> 
> Key: XMLBEANS-175
> URL: http://issues.apache.org/jira/browse/XMLBEANS-175
> Project: XMLBeans
> Type: Bug
> Components: Validator
> Versions: Version 2
> Reporter: Johannes Stamminger
> Attachments: TestExponent.jar, TestExponent.xsd, XMLBeansExponentTest.java
> 
> Having an attribute of type xsd:decimal. Validating a document having set the \
> attribute to "4.2E1" fails with error message "unexpected char '69'" (char '69' is \
> the E). Value "42" works fine. Other XML parsers validate "4.2E1" successfully.
> Parsing fails in org.apache.xmlbeans.impl.values.JavaDecimalHolder#validateLexical(String, \
>                 ValidationContext).
> BTW: according to my XML documentation, type xsd:decimal is "same as \
> java.math.BigDecimal". If this info is correct: IMHO it would be better to rely the \
> BigDecimal-parsing capability ... ?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: dev-help@xmlbeans.apache.org


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic