Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

xml serialization questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jarlaxle - 11 Mar 2008 18:48 GMT
I have an xml serialization question i was hoping someone would know.

If you have a class member that is an array...

[XmlArrayItem("Number")]
public List<int> MyNumbers
{
  get {...}
  set {...}
}

this will get serialized as...

<MyNumbers>
   <Number>1</Number>
   <Number>2</Number>
   <Number>3</Number>
</MyNumbers>

is it possible to have this serialize as a comma-delimited string instead?
i.e...

<MyNumbers>1,2,3</MyNumbers>

if so...what is the best way?
Jarlaxle - 11 Mar 2008 19:40 GMT
Well I think the only way to do it is to override IXMLSerializable and write
the value as you want it.

My question then becomes...how does this affect using the type in a wcf
contract?

It is marked [serializable] also.  I am a little confused on how the
ISerializable and IXMLSerializable interrelate.

Do you have to implement both for binary and xml if you want the object to
be serialized into xml and also binary?

> I have an xml serialization question i was hoping someone would know.
>
[quoted text clipped - 21 lines]
>
> if so...what is the best way?
Ollie Riches - 11 Mar 2008 19:55 GMT
> Well I think the only way to do it is to override IXMLSerializable and write
> the value as you want it.
[quoted text clipped - 35 lines]
>
> - Show quoted text -

Another way is to have another set of properties - the getter would
output the numbers as the comma seperated list and the setter would
process the comma seperated list of numbers...

[XmlIgnore())]
public List<int> MyNumbers
{
   get {...}
   set {...}
}

[XmlElement(Name = "MyNumbers")]
public string MyNumbersAsCSV
{
   get {...}
   set {...}
}

HTH

Ollie Riches

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.