xml serialization questions

  • Thread starter Thread starter Jarlaxle
  • Start date Start date
J

Jarlaxle

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?
 
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?
 
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?



Jarlaxle said:
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...

if so...what is the best way?- Hide quoted text -

- 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
 
Back
Top