Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2006

Tip: Looking for answers? Try searching our database.

Serializing to xml.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sugandh Jain - 28 Dec 2006 09:31 GMT
I am using a method to serialize objects to xml.
this method is working fine to serialize most of the objects to Xml.

For one collection object, it is not doing so. The Collection and its
containing object are marked [Serilizable].

What could be the reasons for the object not getting serialize, and this is
what i get.

<?xml version="1.0"?>
<ArrayOfAllocatedTrade xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
 <AllocatedTrade xsi:nil="true" />
</ArrayOfAllocatedTrade>

Allocated trade is an object with around 10-12 properties.

This is working fine for all other objects, sample right serialization,

<?xml version="1.0"?>
<CloseTradeInterface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <BrokenRulesCollection />
 <CloseTradeFilter>
   <BrokenRulesCollection />
   <CloseTradeDate>2006-12-28T14:59:09.2045251+05:30</CloseTradeDate>
   <Funds>
     <Fund>
       <BrokenRulesCollection />
       <ID>1</ID>
       <ShortName>FundA</ShortName>
       <FullName />
     </Fund>
   </Funds>
   <DataSourceNameID>
     <BrokenRulesCollection />
     <ID>1</ID>
     <FullName />
     <ShortName />
   </DataSourceNameID>
   <AUECListValues>
     <AUEC>
       <BrokenRulesCollection />
       <AUECID>1</AUECID>
       <AUECName>Equity\US\NASDAQ\USD</AUECName>
     </AUEC>
     <AUEC>
       <BrokenRulesCollection />
       <AUECID>11</AUECID>
       <AUECName>Equity\US\ARCA\USD</AUECName>
     </AUEC>
   </AUECListValues>
   <DefaultMethodology>0</DefaultMethodology>
   <Algorithm>1</Algorithm>
 </CloseTradeFilter>
 <NetPositions>
   <Position>
     <BrokenRulesCollection />
     <ID>39f10d1f-a6f0-4dcc-9193-d1404a27babd</ID>
     <ModifiedAt>2006-12-28T15:01:03.8640112+05:30</ModifiedAt>
     <StartDate>2006-12-28T15:01:03.8484049+05:30</StartDate>
     <ModifiedBy>0</ModifiedBy>
     <Symbol>GOOG</Symbol>
     <FundValue>
       <BrokenRulesCollection />
       <ID>1</ID>
       <ShortName />
       <FullName>FundA</FullName>
     </FundValue>
     <AveragePrice>27.4833333333333</AveragePrice>
     <PositionType>Long</PositionType>
     <AUECID>1</AUECID>
     <OpenQty>5500</OpenQty>
     <ClosedQty>5000</ClosedQty>
     <GeneratedPNL>118149.7618333335</GeneratedPNL>
     <PositionTaxLots>
       <AllocatedTrade xsi:nil="true" />
     </PositionTaxLots>
   </Position>
 </NetPositions>
</CloseTradeInterface>
Kevin Spencer - 28 Dec 2006 12:08 GMT
The Serializable Attribute does not make a class serializable as XML.
Serialization encompasses far more than XML Serialization, and is, in fact,
simply defined as the conversion of objects into arrays of bytes that can be
serialized either binarily, or as text.

XML Serialization does not require the Serializable Attribute for
serialization. All you need is the System.Xml.Serialization.XmlSerializer
class to do this. There are, however, a number of attributes that help
control how objects are serialized as XML, and there are some rules
regarding what is and what is not serializable as XML (without any custom
serialization, that is - anything can be serialized as XML using custom
serialization).

According to the SDK, "XML serialization serializes only the public fields
and property values of an object into an XML stream. XML serialization does
not include type information....XML serialization does not convert methods,
indexers, private fields, or read-only properties (except read-only
collections)."

Here are a few helpful links on the topic:

Introducing XML Serialization
http://msdn2.microsoft.com/en-us/library/182eeyhh.aspx

System.Xml.Serialization Namespace
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.aspx

XmlSerializer Class
http://msdn2.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx

Signature

HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

A pea rants as candy be sieving.

>I am using a method to serialize objects to xml.
> this method is working fine to serialize most of the objects to Xml.
[quoted text clipped - 91 lines]
>  </NetPositions>
> </CloseTradeInterface>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.