I have a collection class called Printers that implement the ICollection and
IEnumerable. This class contains a private ArrayList that holds the Printer
objects. The printer class is a serializable class that contains only the
public name attribute.
After serialization, I want to get the following xml structure;
<Printers>
<Printer>
<Name></Name>
</Printer>
<Printers
When I want to serialize this Printers collection, I get instead something
like;
<ArrayOfPrinter>
<Printer>
<Name></Name>
</Printer>
</ArrayOfPrinter
If I take out the ICollection and IEnumerable away, (turning the class into
a normal one) and make the ArrayList public, then I get the following;
<Printers>
<NameOfMyArrayList>
<Printer>
<Name></Name>
</Printer>
</NameOfMyArrayList>
</Printers
For clarity, I don't include any code at the moment.
Any help appreciated,
EthemHello Ethem,
I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
(if its the top level node) or XmlElement attributes will work.
[XmlRoot("Printers")]
public class PrinterCollection
{
// rest of your code
}
--
Matt Berther
http://www.mattberther.com
> Hi,
> I have a collection class called Printers that implement the
> ICollection and IEnumerable. This class contains a private ArrayList
> that holds the Printer objects. The printer class is a serializable
> class that contains only the public name attribute.
> After serialization, I want to get the following xml structure;
> <Printers>
> <Printer>
> <Name></Name>
> </Printer>
> <Printers>
> When I want to serialize this Printers collection, I get instead
> something like;
> <ArrayOfPrinter>
> <Printer>
> <Name></Name>
> </Printer>
> </ArrayOfPrinter>
> If I take out the ICollection and IEnumerable away, (turning the class
> into a normal one) and make the ArrayList public, then I get the
> following;
> <Printers>
> <NameOfMyArrayList>
> <Printer>
> <Name></Name>
> </Printer>
> </NameOfMyArrayList>
> </Printers>
> For clarity, I don't include any code at the moment.
> Any help appreciated,
> Ethem
Hi Matt,
Thanks for the response. Unfortunately, my collection class implements
ICollection and IEnumerable. If the collection implements these interfaces,
you cannot define an XmlRoot attribute (or any other attribute) on the class
level. Same applies if you derive the collection class from the
CollectionBase.
For my problem, I found a workaround in the following site:
http://dotnet.org.za/armand/archive...09/21/4164.aspx
It seems that you can make it programmatically instead of decleratively.
Thanks,
Ethem
"Matt Berther" wrote:
> Hello Ethem,
> I'm assuming you mean XmlSerialization... Given that, either the XmlRoot
> (if its the top level node) or XmlElement attributes will work.
> [XmlRoot("Printers")]
> public class PrinterCollection
> {
> // rest of your code
> }
> --
> Matt Berther
> http://www.mattberther.com
> > Hi,
> > I have a collection class called Printers that implement the
> > ICollection and IEnumerable. This class contains a private ArrayList
> > that holds the Printer objects. The printer class is a serializable
> > class that contains only the public name attribute.
> > After serialization, I want to get the following xml structure;
> > <Printers>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > <Printers>
> > When I want to serialize this Printers collection, I get instead
> > something like;
> > <ArrayOfPrinter>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > </ArrayOfPrinter>
> > If I take out the ICollection and IEnumerable away, (turning the class
> > into a normal one) and make the ArrayList public, then I get the
> > following;
> > <Printers>
> > <NameOfMyArrayList>
> > <Printer>
> > <Name></Name>
> > </Printer>
> > </NameOfMyArrayList>
> > </Printers>
> > For clarity, I don't include any code at the moment.
> > Any help appreciated,
> > Ethem
>
0 comments:
Post a Comment