|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
serialize a property of a collectionI 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 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 > > 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 >> >> > > 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 http://www.mattberther.com/?p=52news:u3HyIuijHHA.1216@TK2MSFTNGP03.phx.gbl... > thanks, but not much help. > using the model from your link or that from 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 > >> > >> > > > > > >
Framework, ProtocolType.Icmp and VISTA
case values in switch statement? Setting required framework version Problem : 2 different ASP .Net running in one IIS Getting 3.0 Facts Straight Are they the same day? 2.0: "Debugging failed because integrated Windows authentication in not enabled" checkboxlist query win32 error How to find the Parent Thread |
|||||||||||||||||||||||