mixed XML serialization

A

andrewcw

I have an object that serializes back and forth.
I would like to have some objects not serialize ..and when
I read that info back into the class, have this item be
null ( or something like it ).

I modified a class I made by XSD.exe by adding these
values ( drvltr, disknum) , but I found when I wrote the
class out to file and retrieved it, the values were
persisted.

If this is reasonable, how do I approach it ? Thanks

In the example below, the tool inserts the declaration
[System.Xml.Serialization.XmlAttributeAttribute()]
for each attribute. Therefore I added the the attributes
drvltr and disknum because I reasoned maybe without the
declaration, they would be ignored.

[System.Xml.Serialization.XmlAttributeAttribute()]
public string uniqueid;
public string drvltr;
public string disknum;
 
K

Kevin Yu

Hi Andrew,

To exclude a field of a class when serializing, you can add the following
attribute before the declaration of this memeber variable. For example, if
you don't want "disknum" to be serialized, you can try the following code:

[System.NonSerialized()]
public string disknum;

This attribute only affects on the declaration of "disknum", and will be
ignored on latter fields.

Does this answer your question? If anything is unclear, please feel free to
reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "andrewcw" <[email protected]>
| Sender: "andrewcw" <[email protected]>
| Subject: mixed XML serialization
| Date: Sun, 5 Oct 2003 20:01:54 -0700
| Lines: 23
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOLtjJlFwrQ4RTLS9eveNRajrJ6Ew==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189133
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| I have an object that serializes back and forth.
| I would like to have some objects not serialize ..and when
| I read that info back into the class, have this item be
| null ( or something like it ).
|
| I modified a class I made by XSD.exe by adding these
| values ( drvltr, disknum) , but I found when I wrote the
| class out to file and retrieved it, the values were
| persisted.
|
| If this is reasonable, how do I approach it ? Thanks
|
| In the example below, the tool inserts the declaration
| [System.Xml.Serialization.XmlAttributeAttribute()]
| for each attribute. Therefore I added the the attributes
| drvltr and disknum because I reasoned maybe without the
| declaration, they would be ignored.
|
| [System.Xml.Serialization.XmlAttributeAttribute()]
| public string uniqueid;
| public string drvltr;
| public string disknum;
|
|
 
D

Daniel Pratt

Hi Andrew,

andrewcw said:
Kevin, something is not right, I modified the class file
and it wrote out the fields and read them back in:
here's what that portion of the class now reads: { What
could be the cause of that ??? } THANKS
<snip>

Use the "XmlIgnore" attribute on the field. The XmlIgnore attribute
refers to XML serialization, whereas the NonSerialized attribute refers to
binary serialization.

Regards,
Dan
 
A

andrewcw

Thanks - I tested that and it worked:
[XmlIgnoreAttribute]
public string disknum;
 
K

Kevin Yu

Thanks, Daniel.

Andrew, apologize for my mistake.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "andrewcw" <[email protected]>
| Sender: "andrewcw" <[email protected]>
| References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
| Subject: Re: mixed XML serialization
| Date: Mon, 6 Oct 2003 11:23:07 -0700
| Lines: 29
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOMNuQWrsIp/RrBSv6Q4v3XXQ5FIg==
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189332
| NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks - I tested that and it worked:
| [XmlIgnoreAttribute]
| public string disknum;
|
| >-----Original Message-----
| >Hi Andrew,
| >
| >| >>
| >> Kevin, something is not right, I modified the class
| file
| >> and it wrote out the fields and read them back in:
| >> here's what that portion of the class now reads: { What
| >> could be the cause of that ??? } THANKS
| ><snip>
| >
| > Use the "XmlIgnore" attribute on the field. The
| XmlIgnore attribute
| >refers to XML serialization, whereas the NonSerialized
| attribute refers to
| >binary serialization.
| >
| >Regards,
| >Dan
| >
| >
| >.
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top