AW: [xsd-users] xsd:decimal and fractation digits
Forstner Michael
Michael.Forstner at cpg.de
Thu Jun 26 07:26:08 EDT 2008
Hi,
I've had the same problem and patched the XSD-Library for my needs:
include/xsd/cxx/tree/serialization.hxx:
inline void
operator<< (xercesc::DOMElement& e, double d)
{
std::basic_ostringstream<char> os;
os.imbue (std::locale::classic ());
os.precision(2); //Patch: ALWAYS 2 fraction digits
// We map both xsd:double and xsd:decimal to double and decimal
[...]
e << s;
}
inline void
operator<< (xercesc::DOMAttr& a, double d)
{
std::basic_ostringstream<char> os;
os.imbue (std::locale::classic ());
os.precision (2); //Patch: ALWAYS 2 fraction digits
// We map both xsd:double and xsd:decimal to double and decimal
[...]
a << s;
}
Hope that helps.
Regards,
Michael
> -----Ursprüngliche Nachricht-----
> Von: xsd-users-bounces at codesynthesis.com
> [mailto:xsd-users-bounces at codesynthesis.com] Im Auftrag von
> Tolonen, Petteri
> Gesendet: Donnerstag, 26. Juni 2008 12:39
> An: xsd-users at codesynthesis.com
> Betreff: [xsd-users] xsd:decimal and fractation digits
>
> Hi,
>
> My problem is too many decimal digits in decimal fields.
> When fractation digits will be supported?
>
> Part of my schema:
> <xsd:complexType name="QuantityType">
> <xsd:sequence>
>
> <xsd:element name="Quantity">
> <xsd:simpleType>
> <xsd:restriction base="xsd:decimal">
> <xsd:totalDigits value="10" />
> <xsd:fractionDigits value="2" />
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:element>
>
> <xsd:element name="QuantityUoM" type="UoMType" />
> </xsd:sequence>
> </xsd:complexType>
>
> I'll set Quantity to 213.23 and result aint what i am looking for.
>
> Result:
> <Quantity>
> <Quantity>213.22999999999999</Quantity>
> <QuantityUoM>kg</QuantityUoM>
> </Quantity>
>
> As i readed posts, i run in to this
> http://codesynthesis.com/pipermail/xsd-users/2007-September/00
> 1215.html
>
> Should i try to make custom decimal type or should i make
> custon type from Quantity with decimal truncation?
> What if there will be more xsd:desimal elements with
> different amount of fractation digits.
> And does it have effect that Quantity's parent element is
> also Quantity?
>
> For note: I can't make changes to schema.
>
> An another thing, i tried to read back the generated xml and i'll get
> these errors for every element:
>
> error: Element 'Quantity' should be un-qualified
>
> Sample xml:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <GI xmlns="MYOWNNAMESPACE"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="MYOWNNAMESPACE MYXSDFILE.xsd">
> ...
>
> <Quantity>213.22999999999999</Quantity>
> ...
> <GI/>
>
>
> Petteri Tolonen
>
>
More information about the xsd-users
mailing list