Error serializing object with serialize (instead of using Save)

Aug 27, 2012 at 9:04 AM

We create a class from an XSD. 

If we use directly Load & Save to deserialize & serialize the object everything works fine.

If we use the object in another one where we need to use Serialize directly we get a wrong XML. We have reproduced the same error using serialize directly on the first object.

For sure there is an our error but we couldn't find it !

Thank's a lot!

 

This is what we get using Save

<FreeForm Version="4">
  <Document DocType="DOCTYPE" Status="0" NumPages="1" Ticket="" ClassificationReponse="RECOGNIZED" SuperTypeCode="3" SuperTypeConfidence="100" SubTypeCode="0" SubTypeConfidence="5">
    <Fields>
      <Field Name="NAME" Value=". . ." Rect="311 92 157 30" AliasRect="183 103 123 19" />
      <Field Name="TIPODOC" Value="DOCUMENTO CARTA D'IDENTITA'" Rect="20 20 10 10" />
    </Fields>
    <Items />
  </Document>
</FreeForm>

This is what we get using Serialize

<FreeForm>
	<FreeForm Version="4">
	  <Document DocType="DOCTYPE" Status="0" NumPages="1" Ticket="" ClassificationReponse="RECOGNIZED" SuperTypeCode="3" SuperTypeConfidence="100" SubTypeCode="0" SubTypeConfidence="5">
		<Fields>
		  <Field Name="NAME" Value=". . ." Rect="311 92 157 30" AliasRect="183 103 123 19" />
		  <Field Name="TIPODOC" Value="DOCUMENTO CARTA D'IDENTITA'" Rect="20 20 10 10" />
		</Fields>
		<Items />
	  </Document>
	</FreeForm>
</FreeForm>

And here is the XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="FreeFormSchema" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" >

	<xs:element name="Field">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Hypo" minOccurs="0" maxOccurs="unbounded">
					<xs:complexType>
						<xs:attribute name="Value" type="xs:string" />
						<xs:attribute name="Rect" type="xs:string" />
						<xs:attribute name="AliasRect" type="xs:string" />
						<xs:attribute name="Page" type="xs:string" />
					</xs:complexType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="Name" type="xs:string" />
			<xs:attribute name="Value" type="xs:string" />
			<xs:attribute name="Rect" type="xs:string" />
			<xs:attribute name="Page" type="xs:string" use="optional" />
			<xs:attribute name="AliasRect" type="xs:string" />
		</xs:complexType>
	</xs:element>

	<xs:element name="Fields">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="Field" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:element name="Document">
		<xs:complexType>
			<xs:sequence>

				<xs:element ref="Fields" minOccurs="1" maxOccurs="1"/>

				<xs:element name="Items" minOccurs="1" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>
							<xs:element name="Item" minOccurs="0" maxOccurs="unbounded">
								<xs:complexType>
									<xs:sequence>
										<xs:element name="ItemField" minOccurs="0" maxOccurs="unbounded">
											<xs:complexType>
												<xs:attribute name="Name" type="xs:string" />
												<xs:attribute name="Value" type="xs:string" />
												<xs:attribute name="Rect" type="xs:string" />
											</xs:complexType>
										</xs:element>
									</xs:sequence>
									<xs:attribute name="Nr" type="xs:string" />
									<xs:attribute name="Page" type="xs:string" />
								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
			<xs:attribute name="DocType" type="xs:string" use ="required" />
			<xs:attribute name="Status" type="xs:string" use ="required" />
			<xs:attribute name="Page" type="xs:integer" use ="required" />
			<xs:attribute name="NumPages" type="xs:integer" use ="required" />
			<xs:attribute name="Ticket" type="xs:string" use ="optional" />
			<xs:attribute name="Rect" type="xs:string" use ="optional" />
		</xs:complexType>
	</xs:element>

	<xs:element name="FreeForm">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="Documents" minOccurs="0" maxOccurs="1">
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="Document" minOccurs="0" maxOccurs="unbounded" />
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element ref ="Document" minOccurs="0" maxOccurs="1" />
			</xs:sequence>
			<xs:attribute name="Version" type="xs:string" use ="required" />
		</xs:complexType>
	</xs:element>
</xs:schema>