xml serialization questions

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

Jarlaxle

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

Ollie Riches

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
 

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