Results 1 to 3 of 3

Thread: [2.0] XML serialization, how do i force the empty fields to be serialized?

  1. #1

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    [2.0] XML serialization, how do i force the empty fields to be serialized?

    Hi!
    i suppose this is a simple question if someone is familiar with xml serialization.
    I'm serializing a class which only consists of some string fields. I want to make sure that all the fields are written to the XML file, even if they are uninitialized empty strings. Is there any way to tell the xml serializer class to enforce this?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: [2.0] XML serialization, how do i force the empty fields to be serialized?

    Add the attribute...
    Code:
    [XmlElement(IsNullable=true)]
    to the fields you want serialized even when null.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: [2.0] XML serialization, how do i force the empty fields to be serialized?

    Quote Originally Posted by crptcblade
    Add the attribute...
    Code:
    [XmlElement(IsNullable=true)]
    to the fields you want serialized even when null.

    i wish i could serialize you as a token of my appreciation. Thanks!
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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