Results 1 to 2 of 2

Thread: [RESOLVED] XML serialization, hide some properties.

  1. #1

    Thread Starter
    Hyperactive Member BramVandenbon's Avatar
    Join Date
    Jan 2002
    Location
    Belgium
    Posts
    502

    Resolved [RESOLVED] XML serialization, hide some properties.

    Hi,

    I am XML-serializing my classes. But when the serialization takes place; all public properties are in the resulting XML-file. But there are certain properties that I do not want to be exported.

    Is there a keyword or way to avoid the serialization of specific properties?

    I tried several articles and tutorials, and even the Microsoft MSDN-library, but I did not find it anywhere.

    Thank you in advance.
    ____________________________________________

    Please rate my messages. Thank you!
    ____________________________________________
    Bram Vandenbon
    http://www.bramvandenbon.com

  2. #2
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: XML serialization, hide some properties.

    Mark them with the NonSerialized attribute...

    eg:
    VB Code:
    1. <NonSerialized()> Public MyString As String

    For a property, try using the XmlIgnore attribute::
    VB Code:
    1. <Xml.Serialization.XmlIgnore()> Public Property MyProperty() As Integer
    2.         Get
    3.             Return Me._int
    4.         End Get
    5.         Set(ByVal Value As Integer)
    6.             Me._int = Value
    7.         End Set
    8.     End Property
    Last edited by Andy_P; Aug 6th, 2006 at 07:00 AM. Reason: Added property example
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width