Rank: Newbie
Joined: 9/16/2009 Posts: 1
|
I have used XMLSPY to ocnvert my xsd into c# class project. When I am creating the XML file one of the element is expecting a decimal. But when I create a Decimal value of 200.00 it removes the precision 00 for some reason and just puts 200 in the XML. So when I validate it against the schema it gives me an error saying that it is expecting decimal. There is no problem when specifying decimal values like 200.12,300.13. But the problem comes when I give 00 as precision value.
|
Rank: Advanced Member
Joined: 7/17/2008 Posts: 185 Location: Minutiae, Triviality
|
Schema:
Code:<?xml version="1.0" encoding="UTF-8"?> <!-- edited with XMLSpy v2009 sp1 (https://www.altova.com) --> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="T_dataone"> <xs:sequence> <xs:element name="datatwo" type="T2_datatwo"/> </xs:sequence> </xs:complexType> <xs:complexType name="T2_datatwo"> <xs:sequence> <xs:element name="datathree" type="xs:decimal" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> <xs:element name="dataone" type="T_dataone"/> </xs:schema>
And this in fooTest.cs:
Code:foo.foo2 doc = foo.foo2.CreateDocument(); foo.T_dataone root = doc.dataone.Append(); foo.T2_datatwo d2 = root.datatwo.Append(); foo.xs.decimalType d3 = d2.datathree.Append(); d3.Value = 1.5M; d3 = d2.datathree.Append(); d3.Value = 2.00M; d3 = d2.datathree.Append(); d3.Value = 3M; d3 = d2.datathree.Append(); d3.Value = 5;
I get this file (which I've DTD/Schema | Assign DTD/Schema... to point at the schema above):
Code:<?xml version="1.0" encoding="utf-8"?> <dataone xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd"> <datatwo> <datathree>1.5</datathree> <datathree>2</datathree> <datathree>3</datathree> <datathree>5</datathree> <datatwo> </dataone>
Which are:
File c:\tmp\foo1.xml is valid. File c:\tmp\foo.xsd is valid.
The file http://www.w3.org/TR/2004/REC-xmlschema-2-20041028/datatypes.html#decimal tells us that:
If the fractional part is zero, the period and following zero(es) can be omitted. For example: -1.23, 12678967.543233, +100000.00, 210.
So:
How are you validating the output? What version of XMLSpy or AltovaXML? Or not Altova at all?
|