Serialization of Types?

Jun 28, 2011 at 12:29 PM

Serializations of Types?

I have a schema that i use to generate classes with xsd2code. I fill the objects with data and then i serialize the objects to xml. The problem is that the serialized xml doesn't validate to the schema. If you look at the serialized xml it contains an extra element level called "tableTextType".

 Schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ArticleTextUpdate"
    targetNamespace="http://tempuri.org/ArticleTextUpdate.xsd"
    elementFormDefault="qualified"
    xmlns="http://tempuri.org/ArticleTextUpdate.xsd"
    xmlns:mstns="http://tempuri.org/ArticleTextUpdate.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
  <xs:element name="articleTextUpdate" type="articleTextUpdate" />
  <xs:complexType name="articleTextUpdate">
    <xs:sequence>
      <xs:element name="articleId" type="xs:int" minOccurs="1" maxOccurs="1" />
      <xs:element name="tableTextInfo" type="tableTextType" minOccurs="0" maxOccurs="unbounded" />
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="tableTextType">
    <xs:sequence>
      <xs:element name="tableText" type="xs:string" minOccurs="1" maxOccurs="1" />
      <xs:element name="tableHeaderText" type="xs:string" minOccurs="1" maxOccurs="1" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

Serialized xml:
<articleTextUpdate>
  <articleId>322608</articleId>
  <tableTextInfo>
    <tableTextType>
      <tableText>1 Table Text</tableText>
      <tableHeaderText>1 Table Header</tableHeaderText>
    </tableTextType>
    <tableTextType>
      <tableText>1 Table Text</tableText>
      <tableHeaderText>1 Table Header</tableHeaderText>
    </tableTextType>
  </tableTextInfo>
</articleTextUpdate> 

If the xml should validate to the original:
<articleTextUpdate>
  <articleId>322608</articleId>
  <tableTextInfo>
      <tableText>1 Table Text</tableText>
      <tableHeaderText>1 Table Header</tableHeaderText>
   </tableTextInfo>
  <tableTextInfo>
      <tableText>1 Table Text</tableText>
      <tableHeaderText>1 Table Header</tableHeaderText>
  </tableTextInfo>
</articleTextUpdate>

Thanks in advance!

Jul 13, 2011 at 1:18 PM

I have exactly the same problem. There is a parent level with node type. thats a shame. Maybe you can configure the Extension to avoid to do that ?

I love this tools !

 

Jul 13, 2011 at 1:37 PM

Just Add

[System.Xml.Serialization.XmlElementAttribute("myNode")]
But you lost automatic generation when you do an update to your xsd
Thanks for your job !