473,401 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

Serialisation - To Display or Not to Display

A general query

Im serialising a person object with the following member variables

Class Person

Private _forenames As String
Private _surname As String
Private _dob As Date
Private _marital_status As MaritalStatus

'Public Get and Set Properties here for each of the above
' I'll not detail them all to save space but Ill show attributes
<XmlElementAttribute(Elementname:="forename")> _
<XmlElementAttribute(Elementname:="surname")> _
<XmlElementAttribute(Elementname:="dob")> _
<XmlElementAttribute(Elementname:="marital_status" )> _
Public Sub New()
End New

Public Enum MaritalStatus
Single,
Married
End Enum

End Class

Say I create a new person:

Dim Dickster as New Person
Dickster.Forename = "mike"
Dickster.Surname = "smith"
It will Serialise as

<Person>
<forename>mike</forename>
<surname>smith</surname>
<dob>1900-01-01</dob>
<marital_status>Single>
</Person>

BUT I didnt set the <dob> and <marital_status> node so i dont want them
to show .

So to work round this i wrapped dates and enumerations in individual
classes...
This was grand but a bit OTT...

Then I discovered ....Specified As Boolean

Private _marital_status As MaritalStatus
Private _marital_statusSpecified As Boolean = False
<XmlElementAttribute(ElementName:="marital_status" )> _
Public Property marital_status() As MaritalStatus
Get
Return _marital_status
End Get
Set(ByVal Value As MaritalStatus)

_marital_status = Value
If Value Is Nothing Then
_marital_statusSpecified = False
Else
_marital_statusSpecified = True
End If
End Set
End Property

<XmlIgnore()> _
Public Property marital_statusSpecified() As Boolean
Get
Return _marital_statusSpecified
End Get
Set(ByVal Value As Boolean)
_marital_statusSpecified = Value
End Set
End Property

Likewise for Dates and Ints
Is there any thoughts about using this means to hide the serilisation
of unset values ?

Thanks

Dickster

Nov 12 '05 #1
3 948
"dickster" <gd***@kerrhenderson.com> wrote in message news:11**********************@g47g2000cwa.googlegr oups.com...
BUT I didnt set the <dob> and <marital_status> node so i dont want them
to show . : : Then I discovered ....Specified As Boolean

Private _marital_status As MaritalStatus
Private _marital_statusSpecified As Boolean = False : : Is there any thoughts about using this means to hide the serilisation
of unset values ?


What you've discovered is the conventional way for handling this
when working with the built-in XmlSerializer.
Derek Harmon
Nov 12 '05 #2
Thanks Derek

I had a look on msdn but couldnt really find anything, was wondering
could you point me in the direction of documentation regarding this.

Dickster

Nov 12 '05 #3
"dickster" <gd***@kerrhenderson.com> wrote in message news:11*********************@f14g2000cwb.googlegro ups.com...
I had a look on msdn but couldnt really find anything, was wondering
could you point me in the direction of documentation regarding this.


http://msdn2.microsoft.com/en-us/lib...checkspecified
Derek Harmon
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: unknow | last post by:
I want to do a serialisation in pure C++ but i don't know how. Do you have some useful links ? Thanks
2
by: msnews.microsoft.com | last post by:
Hi Here is another EASY question When you serialise an object in .NET, serialisation adds defaut attributes that I dont care EXEMPLE : <root_test...
2
by: Greg | last post by:
I have a bizarre situation in which serialisation is failing routinely under a specific condition, and I'm wondering if the details ring a bell with anyone here. I have 2 classes that my...
2
by: ashwinij | last post by:
Hello The steps which i am doing in my program 1) I am having an xml file. 2) I am performing some updations in the file using XQueryUtil class from nux package. 3)After that i am...
1
by: OrionLee | last post by:
I am using C# to work with a 3rd party DLL (Nevron Charts), and attempting to serialise it. The serialisation itself is handled somewhere inside the DLL, so to get it to happen you call the Nevron's...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.