Actually, I was able to find some examples on the MSDN website that's
exactly what I need:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemXmlSerializationXmlAttributesClassXmlDefaultValueTopic.asp

and

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemXmlSerializationXmlAttributesClassXmlIgnoreTopic.asp

Basically, I need to use the XmlAttributes class to extend the metadata for
my classes that I have to serialize. Then, for the attribute of the class, I
can change the XmlIgnore and XmlDefaultValue properties programmatically. In
fact that's the reason I want to skip some of the fields from the encoding -
they can be optional or they can have a default value.

Thanks,
Eddie


-----Original Message-----
From: Unmoderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] Behalf Of Shawn
Wildermuth
Sent: Wednesday, July 06, 2005 3:04 PM
To: [email protected]
Subject: Re: [ADVANCED-DOTNET] Skipping data members in XML
serialization


Unmoderated,

If you want to skip them you can use [NonSerializable], but I suspect you
want to programatically figure it out.  In that case, you'll need to
implement IXmlSerializable.

Thanks,

Shawn Wildermuth
http://adoguy.com
C# MVP, MCSD.NET, Author and Speaker

->-----Original Message-----
->From: Unmoderated discussion of advanced .NET topics.
->[mailto:[EMAIL PROTECTED] On Behalf Of Eduard Lascu
->Sent: Wednesday, July 06, 2005 1:59 PM
->To: [email protected]
->Subject: [ADVANCED-DOTNET] Skipping data members in XML serialization
->
->Hello experts,
->
->Here is another interesting question. I have a simple class
->that is defined like this:
->
->public class BusinessCard
->{
->    public string FirstName;
->    public string LastName;
->    public string Address;
->}
->
->when I am XML-serializing this I get something such as:
->
-><BusinessCard>
->   <FirstName>Lance</FirstName>
->   <LastName>Armstrong</LastName>
->   <Address>Tour de France</Address>
-></BusinessCard>
->
->What I want is to programmatically skip some of the fields
->when I XML-serialize a business card. For example, when
->serializing 100 business card, based on some internal
->conditions, I want to skip the Address field for some of
->them. I know that the XmlIgnore attribute can be used to
->ignore the serialization of some of the members, but how do I
->set it programmatically - the examples I've seen so far would
->set that attribute for the data member at the class
->definition level, which means that the field would be skipped
->always. That's not what I want. I want to be able to decide
->for case to case, whether to skip the field or not.
->
->Any suggestion will be appreciated.
->
->Regards,
->Eddie
->
->===================================
->This list is hosted by DevelopMentorR  http://www.develop.com
->
->View archives and manage your subscription(s) at
->http://discuss.develop.com
07/06/2005 03:03:23 PM

===================================
This list is hosted by DevelopMentor.  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to