Home All Groups Group Topic Archive Search About

serialize a property of a collection

Author
3 May 2007 2:54 PM
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
Author
3 May 2007 7:43 PM
sloan
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.





Show quoteHide quote
"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
>
>
Are all your drivers up to date? click for free checkup

Author
4 May 2007 9:06 AM
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

Show quoteHide quote
"sloan" <sl***@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
>>
>>
>
>
Author
4 May 2007 2:40 PM
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" <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
Show quoteHide quote
> 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" <sl***@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
> >>
> >>
> >
> >
>
>

Bookmark and Share