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

Re: serialize a property of a collection by sloan

sloan
Thu May 03 14:43:06 CDT 2007


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" <bdaniel7@> wrote in message
news:OGUfOMZjHHA.4520@TK2MSFTNGP02.phx.gbl...
> 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
>
>



Re: serialize a property of a collection by Daniel

Daniel
Fri May 04 04:06:39 CDT 2007

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" <sloan@ipass.net> wrote in message
news:ecZuGtbjHHA.4896@TK2MSFTNGP02.phx.gbl...
>
> 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" <bdaniel7@> wrote in message
> news:OGUfOMZjHHA.4520@TK2MSFTNGP02.phx.gbl...
>> 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
>>
>>
>
>



Re: serialize a property of a collection by sloan

sloan
Fri May 04 09:40:58 CDT 2007


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" <bdaniel7@> wrote in message
news:u3HyIuijHHA.1216@TK2MSFTNGP03.phx.gbl...
> 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" <sloan@ipass.net> wrote in message
> news:ecZuGtbjHHA.4896@TK2MSFTNGP02.phx.gbl...
> >
> > 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" <bdaniel7@> wrote in message
> > news:OGUfOMZjHHA.4520@TK2MSFTNGP02.phx.gbl...
> >> 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
> >>
> >>
> >
> >
>
>