Groups | Blog | Home
all groups > dotnet xml > april 2004 >

dotnet xml : Conditionally render during serialization


Noah Subrin
4/7/2004 3:25:16 PM
Hello,

I have a class like the following

public class person
public FirstName as string
public LastName as string

end class


I am serializing the class. I want to conditionally not render a property if
it is blank. For example if LastName = "", I don't want to display it.

I am serializing it using the following:



Dim p as person = new Person

p.FirstName = "John"



Dim sw As StringWriter = New StringWriter

Dim ser As XmlSerializer = New XmlSerializer(GetType(Person))

ser.Serialize(sw,p)

Any ideas?



Thanks in advance.





Alex Shirshov
4/9/2004 11:28:10 AM
Hello, Noah!
You wrote on Wed, 7 Apr 2004 15:25:16 -0500:

NS> I have a class like the following

NS> public class person
NS> public FirstName as string
NS> public LastName as string

NS> end class

NS> I am serializing the class. I want to conditionally not render a
NS> property if it is blank. For example if LastName = "", I don't want to
NS> display it.

It may be done by implementing IXmlSerializable interface.

[Sorry, skipped]


With best regards, Alex Shirshov.

AddThis Social Bookmark Button