[xsd-users] losing double precision in output xml (msvc++7.1)

Boris Kolpackov boris at codesynthesis.com
Wed Mar 15 07:06:03 EST 2006


Fred,

Fred Campaigne <fcampaigne at accesswave.ca> writes:

> Just started using xsd and it is a hit.  Makes machine generated xml a
> breeze.  I am having a problem with loss of precision of doubles in the
> output xml, as follows:
>
> std::ostream ofs("outfile.xml", std::ios_base::binary);   //non binary
> is the same
> ofs.precision(12);   //values used in the cxx-tree generated objects are
> accurate to many places
> GridSearchData(ofs, *gsd, map);   //generate the xml to ofs
> std::cout << ofs.precision() << std::endl;  // this prints 12
>
> and my double precision latitudes and longitude have float precision in
> the streamed xml.

I think it's a bug. The float, double and long double types should be
parsed and serialized with their maximum precisions. I made precision
for double 12 and for long double 24. You can get the fixes here:

http://codesynthesis.com/~boris/tmp/libxsd-2.0.0-2.zip

I tried this on the following test case:

<!-- test.xsd -->
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <xsd:element name="test" type="xsd:double"/>

</xsd:schema>


// driver.cxx
//
#include <iostream>
#include "test.hxx"

using std::cerr;
using std::endl;

int
main ()
{
  double value (1.123456789123);

  xml_schema::namespace_infomap map;
  test (cerr, value, map);
}


It prints:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<test>1.123456789123</test>


Thanks for reporting this!
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060315/625ea850/attachment.pgp


More information about the xsd-users mailing list