Re: Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????
From: Daniel Cazzulino [MVP XML] (kzuAT_at_NOaspnet2SPAMPLZ.com)
Date: 06/28/04
- Next message: September: "Web Service returns 404"
- Previous message: Daniel Cazzulino [MVP XML]: "Re: There MUST be a better way..."
- In reply to: Bob Rock: "Re: Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????"
- Next in thread: Ming Chen [.NET MVP]: "Re: Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 28 Jun 2004 13:40:35 -0300
You can use:
[WebMethod]
[return: XmlArray("Customers")]
public Customer[] GetCustomers()
HTH
-- Daniel Cazzulino [MVP XML] Clarius Consulting SA http://weblogs.asp.net/cazzu http://aspnet2.com "Bob Rock" <nospam.yet_another_apprentice@hotmail.com> wrote in message news:eEQ$5gEVEHA.1656@TK2MSFTNGP09.phx.gbl... > > > Ahhh, so that is the way you can use the XmlArrayAttribute and > > > XmlArrayItemAttribute on something that is not a field!!! > > > Is it possible to use it on methods returning arrays??? > > > > Methods can return instances of Foo. Those instances of Foo will behave > as > > indicated by the attributes on Foo. > > If your method returns an array, then the attributes that apply are those > on > > the base type. > > So if it is an array of Foo that is being returned, then the attributes on > > the Foo definition will apply to the elements of the array. > > The point here is not controlling the serialization of the elements of an > array, but of the array itself, in other words of the xml root element. > > > I believe it is not possible to effectively attribute arrays if they are > not > > serialized as members of classes. In other words, if it is a local > variable > > and you want to serialize it, I believe the attributes do not apply. > > That is not true ... controlling serialization of a class field that is an > array is indeed very simple (XmlArrayAttribute and XmlArrayItemAttribute is > all that is needed). > > > Also > > if the array is a member variable and you do not serialize the entire > class, > > then I believe the attributes do not apply. > > > > > I've also seen that there is a way of setting the root node element to > > > whatever one wants using the XmlSerializer(Type, XmlRootAttribute) > > > constructor. Unfortunately when deserializing I need to change the root > > node > > > element to <ArrayOfClassname> as the XmlSerializer expects to avoid the > > > exception. > > > > Yes this should work, but I don't understand what the problem is on > > de-serializing. If you are using the same kind of XmlSerializer > > (constructed with the XmlRootAttribute), then the string or stream with > the > > modified root node should de-serialize just fine. eg > > Again, this is not true. Using the XmlSerializer constructor with the > XmlRootAttribute parameter lets you control only serialization ... it does > not make the XmlSerializer instance *understand* an xml with the root node > set to the XmlRootAttribute parameter you are passing in when using that > XmlSerializer instance to deserialize an xml into the array. It *still* > expects the xml that it would generate normally (the one with > <ArrayOfClassname>). > > > > > >Sorry for the cross-posting, but it is done only in the hope that more > > people may read (and hopefully answer) my post. > > > > >. Yes, more people see it. But not more > > people who care, or who will have anything to contribute. > > This is just your personal opinion. > I posted not on *any* NG, but on NGs that I felt are visited by people that > could have the answer I was looking for .... xml or web services newsgroups > (and I believe serialization is something that should be well known by > people dealing with WS). > > > You could also > > ask xml serialization questions to people you meet in the subway on the > way > > to work, or at church, or in the stands at the ballgame, but I doubt > you'll > > have much success there either. > > > > Imagine if everyone followed your policy. Every question on every topic > > would get asked on every group. Would that work? The different groups > are > > set up to raise the signal-to-noise ratio. If only works if the > > participants follow the conventions. > > > > Sometimes cross-posts make sense because it is not clear what area the > > question would fall under. 2 groups is reasonable. 3 is about the limit. > > 4 is egregious. > > > > I am not making any of this up. This is just standard netiquette. > > http://www.google.com/search?hl=en&num=30&q=netiquette+cross+posting > > > > > > -D > > > > Bob Rock > > > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.708 / Virus Database: 464 - Release Date: 18/06/2004
- Next message: September: "Web Service returns 404"
- Previous message: Daniel Cazzulino [MVP XML]: "Re: There MUST be a better way..."
- In reply to: Bob Rock: "Re: Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????"
- Next in thread: Ming Chen [.NET MVP]: "Re: Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading