I haven't tried this but in general XmlSerializer uses XmlRoot attribute to
control this.
You can also try XmlTypeAttribute

Steven Livingstone wrote:

> Hi All. I have a hopefully quick question.
> I have a class derived from ArrayList and have it serializing fine with
> a bunch of items i add to the list.
>
> The very basic WS method (with nothing added to the collection - that part
> works exactly as i want) is shown below :
>
> [WebMethod]
> public ItemACollection GetCols()
> {
>  public ItemACollection a = new ItemACollection();
>
>  return a;
> }
>
> The output is as follows :
>
> <?xml version="1.0" encoding="utf-8"?>
> <ArrayOfItemA
>  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>  xmlns="myuri:someuri" />
>
> My problem is simply this - i do not want the "ArrayOfItemA" appearing at
> the root here - I would rather have my own custom root element.
>
> I think i have tried everything (i thought it would be real simple), both
> within this class and within the ItemACollection class and can't seem to
> get it. I have looked around, but not found an answer to this.
>
> I would have hoped something like the following would have worked as I
> successfully used the following technique to serialize other ArrayList
> derived instances, but it is actually controlling the root element that is
> driving me nuts here. Any ideas?
>
>  public class ItemACollection : ArrayList
>  {
>
>   [XmlArray("AItems")]
>   [XmlArrayItem("AItem", typeof(ItemA))]
>   public new ItemA this [int index]
>   {
>    get
>    {
>     return(ItemA)base[index];
>    }
>
>    set
>    {
>     base[index] = value;
>    }
>   }
>
>   public int Add(ItemA value)
>   {
>    return base.Add (value);
>   }
>  }
>
> I am continuing to look at this when i get 5 mins and i'll mail back it i
> get it.
>
> thanks,
> Steven
> http://www.stevenlivingstone.com
>
> ===================================
> This list is hosted by DevelopMentor�  http://www.develop.com
> NEW! ASP.NET courses you may be interested in:
>
> 2 Days of ASP.NET, 29 Sept 2003, in Redmond
> http://www.develop.com/courses/2daspdotnet
>
> Guerrilla ASP.NET, 13 Oct 2003, in Boston
> http://www.develop.com/courses/gaspdotnet
>
> View archives and manage your subscription(s) at http://discuss.develop.com

Steven Livingstone wrote:

> Hi All. I have a hopefully quick question.
> I have a class derived from ArrayList and have it serializing fine with
> a bunch of items i add to the list.
>
> The very basic WS method (with nothing added to the collection - that part
> works exactly as i want) is shown below :
>
> [WebMethod]
> public ItemACollection GetCols()
> {
>  public ItemACollection a = new ItemACollection();
>
>  return a;
> }
>
> The output is as follows :
>
> <?xml version="1.0" encoding="utf-8"?>
> <ArrayOfItemA
>  xmlns:xsd="http://www.w3.org/2001/XMLSchema";
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>  xmlns="myuri:someuri" />
>
> My problem is simply this - i do not want the "ArrayOfItemA" appearing at
> the root here - I would rather have my own custom root element.
>
> I think i have tried everything (i thought it would be real simple), both
> within this class and within the ItemACollection class and can't seem to
> get it. I have looked around, but not found an answer to this.
>
> I would have hoped something like the following would have worked as I
> successfully used the following technique to serialize other ArrayList
> derived instances, but it is actually controlling the root element that is
> driving me nuts here. Any ideas?
>
>  public class ItemACollection : ArrayList
>  {
>
>   [XmlArray("AItems")]
>   [XmlArrayItem("AItem", typeof(ItemA))]
>   public new ItemA this [int index]
>   {
>    get
>    {
>     return(ItemA)base[index];
>    }
>
>    set
>    {
>     base[index] = value;
>    }
>   }
>
>   public int Add(ItemA value)
>   {
>    return base.Add (value);
>   }
>  }
>
> I am continuing to look at this when i get 5 mins and i'll mail back it i
> get it.
>
> thanks,
> Steven
> http://www.stevenlivingstone.com
>
> ===================================
> This list is hosted by DevelopMentor�  http://www.develop.com
> NEW! ASP.NET courses you may be interested in:
>
> 2 Days of ASP.NET, 29 Sept 2003, in Redmond
> http://www.develop.com/courses/2daspdotnet
>
> Guerrilla ASP.NET, 13 Oct 2003, in Boston
> http://www.develop.com/courses/gaspdotnet
>
> View archives and manage your subscription(s) at http://discuss.develop.com

--
NOTICE: If received in error, please destroy and notify sender.  Sender does
not waive confidentiality or privilege, and use is prohibited.

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
NEW! ASP.NET courses you may be interested in:

2 Days of ASP.NET, 29 Sept 2003, in Redmond
http://www.develop.com/courses/2daspdotnet

Guerrilla ASP.NET, 13 Oct 2003, in Boston
http://www.develop.com/courses/gaspdotnet

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to