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

0
gdick (75)
10/31/2005 2:26:34 PM
dotnet.xml 7266 articles. 0 followers. Follow

3 Replies
568 Views

Similar Articles

[PageSpeed] 30

"dickster" <gdick@kerrhenderson.com> wrote in message news:1130768794.072334.165240@g47g2000cwa.googlegroups.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 


0
loresayer (276)
11/1/2005 12:08:20 AM
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

0
gdick (75)
11/1/2005 11:15:42 AM
"dickster" <gdick@kerrhenderson.com> wrote in message news:1130843742.635424.27400@f14g2000cwb.googlegroups.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/library/system.xml.serialization.xmlmembermapping.checkspecified


Derek Harmon 


0
loresayer (276)
11/2/2005 3:48:45 AM
Reply:

Similar Artilces:

Unable display folder
Hi, My system can not receive email. I upgrade it from Office 2000 to Office XP. Screen has message: Unable to display the folder. Microsoft outlook could not access the specified folder location. The .DLL file for the information service could not be found. MAPI was unable to load the information service PSTRX.DLL. Be sure the service is correcty installed and configured. I need help. Please email me cchen@glbtecx.com or call 949 450 8725. Thank you. .. ...

Shortcut to display formulas ?
Hi, I work in France, with an AZERTY keyboard, and I use Vista Home, french version, Excel french versions Excel Help (2002, 2003, 2007) says that to display formulas instead of values (and back) I must hit CTR+ ` This second character is what I can get when I hit AltGr+7. But trying to type AltGr + CTRL + 7 or CTRL+AltGr+7 does not do anything. I tried to switch to a QWERTY keyboard (Alt + Shift for 3 seconds), this ` is now where I had the � character, but CTRL + � does no good. So back to AZERTY... I know how to make formulas appear (Options...) but a shortcut is much faster. Can any...

Money 2004 Premium download transactions not displayed in account.
After I download statements into Money 2004 premium, they are not displayed in the register. A notice that I have statements to read appears in the Home Page Reminders window. Money shows that transactions have been downloaded in the Accounts list, but the transactions are not displayed in the account. I have found similar knowledge base messages for Money 2002 Delux & Business. I have run the standard repare program. That produced a warning that broken records exist in the system table. The program did not fix the problem. I re-installed the Money Program Problem still exists. ...

Display lists in an arbitrary number of columns
I have written and posted the following articles which will prove useful = to some: Display Lists in Columns Horizontally Using One Cell per Column http://www.braintrove.com/default.aspx?p=3D3&s=3D1&i=3D34 Display Lists in Columns Horizontally Using Individual Cells http://www.braintrove.com/default.aspx?p=3D3&s=3D1&i=3D33 Display Lists in Columns Vertically Using One Cells per Column http://www.braintrove.com/default.aspx?p=3D3&s=3D1&i=3D32 Display Lists in Columns Vertically Using Individual Cells http://www.braintrove.com/default.aspx?p=3D3&s=3D1&i=3D31 ...

UINT Serialisation
Hi, I have a bug in some of my predecessors code, i am trying to fix it, but i dont understand how it works in the first place. perhaps someone can help. I have this object. class MY_CLASS { public: MY_CLASS (); UINT var1:3; UINT var2:1; UINT var3:1; UINT var4:1; UINT var5:1; UINT var6:1; UINT var7:1; UINT var8:1; UINT var9:8; UINT var10:14; friend CArchive& operator << ( CArchive& os, MY_CLASS &); friend CArchive& operator >> ( CArchive& is, MY_CLASS &); }; now in the read and writing methods represented by >> and << are this CArchive&...

How do I display the "&" in the footer?
Our company name contains the "&" but I cannot get it to appear when I type it in the custom footer. IE: Shoes & Socks Inc. appears as "Shoes Socks Inc. We have Office 200 & Office XP and it happens in both versions of Excel. Hi Que_66! Use: Shoes && Socks Inc. -- Regards Norman Harker MVP (Excel) Sydney, Australia njharker@optusnet.com.au Excel and Word Function Lists (Classifications, Syntax and Arguments) available free to good homes. "Que_66" <anonymous@discussions.microsoft.com> wrote in message news:9B40E2F6-A8B5-4F04-84AA-6A6C1B16A...

Dates display inconsistent in MS Excel 2007
I have two files with the same date ranges (Jun-01 thru Jun-09), but in the chart one file shows Jan not Jun. The only difference is the format, in the first file the first date is shown as a number format with value of , whereas in the second file it is shown as a date mmm-yy. Can someone explain why this is happening? I can send the files if you want to see exactly how the dates are entered. Please assist. Thanks! ...

Displaying Scenarios
I have set up a number of scenarios on a worksheet as they relate to different versions of my budget. Rather than having to go in everytime and display each one individuall, I would like to enter a parameter in one cell that will automatically display the right scenarios. Hopefully, using a conditional statement of some kind. Any help would be greatly appreciated. Jeffrey Albaum Controller Jet Moulding Compounds Inc. Ajax, Ontario, Canada How about a worksheet_change event? I created a couple of custom views and then rightclicked on the worksheet tab that held the important cell. ...

Displaying Comments
I have trouble displaying any comments that are entered into either Word or PowerPoint docs by a Windows Office 2003 user. I am running MAC OS 10.3.7 and have tried to fix this in both Office X and the Office 2004 Demo without success. I have "View Comments" checked and if I enter a comment, I can see it. Thank you. Russ ...

Displaying listbox selection in textbox
I av a problem trying to create a macro that the selection made in listbox(List1) to be displayed in a textbox(Text1). here is the code that i did so far but i cant get it to work: Sub Expense_Select() 'Link the data to the listbox Range("G7:G18").Select ActiveSheet.Shapes("List1").Select With Selection .ListFillRange = "$G$7:$G$19" .LinkedCell = "" .MultiSelect = xlNone .Display3DShading = False End With End Sub Private Sub List1_Click() 'display the selected item in the textbox Text1.Text = List1.List(List1.ListIndex) End Sub ANY sugg...

Pie Chart not to display 0 Values
Good day, I have an excel Table something like below. Column A Column B Item 1 24% Item 2 13% Item 3 0% Item 4 3% Item 5 0% The Values in Column B are being automatically updated from another table. There are 24 Items in the table and usually about 10 of them are 0, in a given period of time. Is there any way that the chart can be intelligent enough to skip the 0 Values and display only values greater than 0. This would clear the clutter on the chart. I am using a pie chart for the purpose. Thanks for Help _________________ Best Regards Khawar Andy Pope has instructions on his web sit...

OWA
Exchange 2003 SP1 Can you change how long this message is displayed for ? I'd like to increase it to a least a minute or perhaps longer. Thanks in advance Dom ...

Reversing display name in GAL
Is there any easy way to do a Point-and-click change to reverse the default display name of the recipients within the Global Address List so that they show up as LastName, FirstName vs the opposite. I found that you can change the Display Names of the Active Directory Users via MS 250455 but is this the way that you'd modify the Exchange GAL. Thank you. Unfortunatly I don't think there is a easy Point-and-click way. You can do an LDAP export and modify the ldif file with scripts the import it back in. That can be risky if you are not familiar with LDAP import/export. I ...

Is it possible to display a character, but utilize a value in the same cell?
I am working on a schedule of inspections. I have a column that displays either a Q(Quarterly), S(Semi-Annual) or A(Annual) . I'd like to be able to link the column to an equation with the values 4, 2, or 1. (IE Quarterly is 4 inspections a year) Can a "Q" be displayed in a cell, but use a math value of 4 as part of an equation for further calculations For Example: Cell A I Cell B I Cell C I Cell D Qty I Insp I Hours I Total 2 Q .75 (2 x 4 x .75) = 6 inspection hours Annually I'd like the sheet to display the type of insp...

Serialisation with ActiveX
Hi, I'm no MFC expert so I might not use the correct terms. I'm working on an application that consists of a .exe with a DLL extension DLL and an ActiveX ocx. The ActiveX attempts to serialise some objects declared in the extension DLL but it can't find them. I read something about this after a google search but I didn't really get much help. I think I've fixed it but it's a bit of a hack. I get the Afx module state in the extension DLL and store that value away. Before I call any code in the ActiveX DLL that might use serialisation, I use AFX_MANAGE_STATE to set...

Help with Display Setting
Hi All, I designed an Excel Spreadsheet that not only contains programmed dropdowns and checkboxes, but other text line fill ins that cannot be resized due to the current design. Because of the structure, I’m now running into problems with certain users in regards to their Display setting of 120 DPI vs. the traditional 96 DPI. When I originally developed this, I set the spreadsheet to function at 100% Zoom level based on the assumption all users were set to 96 DPI. All of the checkboxes and fill ins are dependant on this setting. Without this size, the viewing screen is decreased and s...

Displaying an equation
I have an equation setup that is referencing a few other cells that have equations in them. I want to have a cell that displays this equation with the answers that are calculated from these other cells displayed as values in the new equation. Any help would be greatly appreciated. Thanks Check out http://www.mvps.org/dmcritchie/excel/formula.htm#getformula In article <E4143E2B-360A-4B43-955F-73BF8EC60694@microsoft.com>, "hoising8" <hoising8@discussions.microsoft.com> wrote: > I have an equation setup that is referencing a few other cells that have > eq...

Serialisation
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"...

New Email does not display
When new email arrives you don't know it. You don't know you have new mail until you click on an existing email in your inbox. Any ideas? It's a setting. But... 1. You don't tell us the program you're using. 2. We can't guess if it's Outlook or Outlook Express. 3. This is the Excel newsgroup; you're in the wrong place. :) ******************* ~Anne Troy www.OfficeArticles.com "Travis" <Travis@discussions.microsoft.com> wrote in message news:D864BC01-7D98-48DA-A132-614D02E45963@microsoft.com... > When new email arrives you don't know ...

Display hint in CListCtrl
I have a list control that displays several items, I want to display a detailed description when i'm hoverring above an item, currently i'm using th mouse button click for displaying that hint, Does anyone how this can be done automatically? Thanks. "Jeto" <yuval.gatenio@gmail.com> wrote in message news:1142512301.568848.307100@j33g2000cwa.googlegroups.com... > I have a list control that displays several items, > I want to display a detailed description when i'm hoverring above an > item, > currently i'm using th mouse button click for displaying ...

Contact Display Names
I was wounder if this can be done with Outlook. When I enter my contacts in the contacts lists, will this change the name shown when email comes in, and can this even be change. Example: an email comes in as test@test.com (with display name Test1), I would like to have the contacts name shown as MyTest. Is this possible? Thanks in advance. typically incoming mail uses the display name the sender has configured in their mail client. -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Ou...

Xsd and serialisation
hello, I wonder if anyone can help me. I have used xsd to generate a c# class from an xml file. This class is currently being used in my application and works perfectly ok when stored in InProc session. But when moving to StateServer, it throws the "Unable to serialize the session state", now I know the reasons why it throws this error. But I have a very simple xml structure (and in turn a simply generated class). Can anyone help me. The XML structure is simple, i.e. <AAAs> <AAA Name="x" Type="y"> <BBB x="1" /> <CC...

OWA Not displaying any graphics
Good afternoon group, I have a problem at one exchange site that I can't find a solution for. We have Exchange 2003 and OWA is not displaying any of the graphics. The only way I can get the graphics for OWA to load is to restart the iisadmin service. Is this a security permission that I am not seeing? It reoccurs every 8 hours or so. Anyone ever run into this problem? The authenticated users and anonymous users have read access to the exchange web folder. Anyone know what I could do to not have to schedule a restart of iisadmin ever 8 hours? Most humbly appreciated! Nick Are you gett...

How to display array of strings via Format-Wide
Has anybody tried to display collection of strings using Format-Wide? It works, but everytime only one column is used. Example: [1]:> '1', '2', '3', '4', '5' | format-wide -autosize 1 2 3 4 5 I have no idea how to persuade Posh to use more columns or accept - autosize switch. The only way that works is this one: '1','22','333','4444','55555' | % { new-object psobject -prop @{This= $_}} | Format-Wide -Property This -autosize i.e. creating new psobject with a noteproperty [string]@('1'...

Displaying Asian Languages
Does anyone know how to get documents containing Asian text (such as Chinese, Korean and Thai) to display in Office vX (in OS X)?... On Tue, 18 May 2004 11:12:19 -0500, leo mac wrote (in article <eac901c43cf2$e4c7ad60$a601280a@phx.gbl>): > > Does anyone know how to get documents containing Asian text (such as > Chinese, Korean and Thai) to display in Office vX (in OS X)?... You need Unicode support. Only Word 2004 offers it, you can't get it in X. Corentin -- --- Mac:MS MVP (Francophone) --- (MS) MVP: http://mvp.support.microsoft....