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 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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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>
.......
..........
|
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. ...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
| |