serialize a property of a collection

D

Daniel

Hi,
I have a collection, which is a property of a class:
public class PostcodeCollection : CollectionBase
{
// ...collection specific properties
[XmlAttribute("Total")]
public int Total
{
get { return List.Count; }
set {}
}
}

The main class is:
[XmlRoot("PostCodes" )]
public class PostcodeReport
{
// ..other properties
[XmlArray("Updated")]
[XmlArrayItem(typeof(PostCodeLine), ElementName="PostCode")]
public PostcodeCollection Updated
{
get { return this.updated; }
}
}

I want to add the "Total" property as an attribute to "Updated" node.
Using "XmlAttribute" on the property, doesn't do the trick.

This is how the xml must look like:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='PostcodeUpdates.xslt'?>
<PostCodes Generated="03-05-2007, 17:50">
<Added />
<Updated Total="23" >
<PostCode District="2031"... />
</Updated>
</PostCodes>

How can i do this?

Many thanks,
Daniel
 
D

Daniel

thanks, but not much help.
using the model from your link or that from http://www.mattberther.com/?p=52
requires that i serialize manually each collection.
and this is too much, i have already 4 collections in my report and other
might come in.

i'm shocked anyway that for such a simple task i have to do things
manually...

Daniel

sloan said:
See this blog entry:
9/21/2005
XmlSerialization with IDictionary and CollectionBase Objects
http://sholliday.spaces.live.com/blog/

It may or may not help.

I just know xml serialization gets finicking on CollectionBase
(IDictionary)
objects.





Daniel said:
Hi,
I have a collection, which is a property of a class:
public class PostcodeCollection : CollectionBase
{
// ...collection specific properties
[XmlAttribute("Total")]
public int Total
{
get { return List.Count; }
set {}
}
}

The main class is:
[XmlRoot("PostCodes" )]
public class PostcodeReport
{
// ..other properties
[XmlArray("Updated")]
[XmlArrayItem(typeof(PostCodeLine), ElementName="PostCode")]
public PostcodeCollection Updated
{
get { return this.updated; }
}
}

I want to add the "Total" property as an attribute to "Updated" node.
Using "XmlAttribute" on the property, doesn't do the trick.

This is how the xml must look like:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='PostcodeUpdates.xslt'?>
<PostCodes Generated="03-05-2007, 17:50">
<Added />
<Updated Total="23" >
<PostCode District="2031"... />
</Updated>
</PostCodes>

How can i do this?

Many thanks,
Daniel
 
S

sloan

Are you saying you can't create a wrapper.


class MyReportInfo
(with these members)
PeopleCollection
StateCollection
CountyCollection


and serialize that one (wrapper) object?


//Matt Quote
The drawback is that I have to have a container class, as these attributes
can't be applied to a class. Not necessarily my first choice, but, I suppose
it will do.
//



Daniel said:
thanks, but not much help.
using the model from your link or that from http://www.mattberther.com/?p=52
requires that i serialize manually each collection.
and this is too much, i have already 4 collections in my report and other
might come in.

i'm shocked anyway that for such a simple task i have to do things
manually...

Daniel

sloan said:
See this blog entry:
9/21/2005
XmlSerialization with IDictionary and CollectionBase Objects
http://sholliday.spaces.live.com/blog/

It may or may not help.

I just know xml serialization gets finicking on CollectionBase
(IDictionary)
objects.





Daniel said:
Hi,
I have a collection, which is a property of a class:
public class PostcodeCollection : CollectionBase
{
// ...collection specific properties
[XmlAttribute("Total")]
public int Total
{
get { return List.Count; }
set {}
}
}

The main class is:
[XmlRoot("PostCodes" )]
public class PostcodeReport
{
// ..other properties
[XmlArray("Updated")]
[XmlArrayItem(typeof(PostCodeLine), ElementName="PostCode")]
public PostcodeCollection Updated
{
get { return this.updated; }
}
}

I want to add the "Total" property as an attribute to "Updated" node.
Using "XmlAttribute" on the property, doesn't do the trick.

This is how the xml must look like:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='PostcodeUpdates.xslt'?>
<PostCodes Generated="03-05-2007, 17:50">
<Added />
<Updated Total="23" >
<PostCode District="2031"... />
</Updated>
</PostCodes>

How can i do this?

Many thanks,
Daniel
 

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