Results 1 to 4 of 4

Thread: serializing empty xml element

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    59

    serializing empty xml element

    Hi,

    i am using System.Xml.Serialization;

    how can i serialize an empty element output <something /> ?

    current, after serialize an empty element, it wont show, only not null element wil be output.

    Please advise.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    Tulsa,Ok
    Posts
    262

    Re: serializing empty xml element

    My first question would be, why do you want to serialize something that does not contain any information? Why not just check on the deserialize side and take action if that object and / or variable is null or empty?

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464

    Re: serializing empty xml element

    You can add an attribute above your property:


    <XmlElement(isnullable:=True)>
    public string Something;

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    59

    Re: serializing empty xml element

    Quote Originally Posted by Phenglai
    My first question would be, why do you want to serialize something that does not contain any information? Why not just check on the deserialize side and take action if that object and / or variable is null or empty?

    eg.

    <car>
    <door>door 1</door>
    <door>door 2</door>
    <alarm>alarm brand</alarm>
    </car>
    <car>
    <door>door 1</door>
    <door>door 2</door>
    <alarm/>
    </car>


    Not every car has alarm but i want to show as an empty tag instead of no tag.

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