473,386 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Serialization Question

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
Nov 19 '05 #1
2 1104
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

Nov 19 '05 #2

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/...9/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


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Bob Rock | last post by:
Hello, when serializing an array of elements of a class Classname using XmlSerializer.Serialize() I get an XML like the following: <?xml version="1.0"> <ArrayOfClassname> ....... ..........
3
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. ...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
6
by: Uttam | last post by:
Hello, We are at a very crucial decision making stage to select between .Net and Java. Our requirement is to download a class at runtime on the client computer and execute it using remoting or...
0
by: eSapient | last post by:
I generated serialization/deserialization code for this schema using the xsd tool: <?xml version="1.0" encoding="UTF-8"?> <xs:schema elementFormDefault="qualified"...
6
by: John Glover | last post by:
I'm having a very strange problem with XML serialization. I'm writing web services which pass instances of various classes back and forth as parameters and return values of web methods. The...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
0
by: groovyghoul | last post by:
Hi I have the following XML file: =========================================================== <?xml version="1.0" encoding="UTF-16"?> <Policy xmlns="http://tempuri.org/richard.xsd"> <TransType...
0
by: nobin01 | last post by:
Dear sir; I want ur Help in serialization.I know serialization.I Know binary,soap and xmlserialization also.But i want ur help in following topics.pls help me as soon as possible.I have search in...
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.