473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Serialization:: Too many ArrayList elements

I'm using XML Serialization to try and get this structure:

<LibraryCategories>
<LibraryCatgeory>1</LibraryCatgeory>
<LibraryCatgeory>2</LibraryCatgeory>
<LibraryCatgeory>3</LibraryCatgeory>
</LibraryCategories>

My class has a public property called LibraryCategories, of type ArrayList:

[XmlElement(Type = typeof(LibraryCategoryItem))]
public ArrayList LibraryCategories;

In addition, I have class which defines the LibraryCategory item:

public class LibraryCategoryItem
{
public string LibraryCategory;
}
The problem is, the Serialized XML takes this structure

<LibraryCategories>
<LibraryCatgeory>1</LibraryCatgeory>
</LibraryCategories>
<LibraryCategories>
<LibraryCatgeory>2</LibraryCatgeory>
</LibraryCategories>
<LibraryCategories>
<LibraryCatgeory>3</LibraryCatgeory>
</LibraryCategories>
What attributes do I need to place on the LibraryCategories and/or the
LibraryCategoryItem class to enforce the desired XML?
Nov 12 '05 #1
2 1193
"Codex Twin" <co***@gmail.com> wrote in message news:42***********************@ptn-nntp-reader01.plus.net...
My class has a public property called LibraryCategories, of type ArrayList:

[XmlElement(Type = typeof(LibraryCategoryItem))]
public ArrayList LibraryCategories;
This should have the following attributes on it to achieve your desired outcome,

[XmlArray("LibraryCategories")]
[XmlArrayItem("LibraryCategory", typeof(LibraryCategoryItem))]
public ArrayList LibraryCategories;

I observe there was a consistent typo in the target XML you've requested (it
says LibraryCatGEory instead of LibraryCatEGory). If that is intentional, then
use [XmlArrayItem("LibraryCatgeory", typeof(LibraryCategoryItem))] here
instead.
In addition, I have class which defines the LibraryCategory item:

public class LibraryCategoryItem
{
public string LibraryCategory;
}


Further, to prevent the LibraryCategory field from being wrapped in an
element itself you must make it a text node with the following attribute,

[XmlText( )]
public string LibraryCategory;
Derek Harmon
Nov 12 '05 #2

"Derek Harmon" <lo*******@msn.com> wrote in message
news:O5**************@TK2MSFTNGP10.phx.gbl...
"Codex Twin" <co***@gmail.com> wrote in message
news:42***********************@ptn-nntp-reader01.plus.net...
My class has a public property called LibraryCategories, of type
ArrayList:

[XmlElement(Type = typeof(LibraryCategoryItem))]
public ArrayList LibraryCategories;


This should have the following attributes on it to achieve your desired
outcome,

[XmlArray("LibraryCategories")]
[XmlArrayItem("LibraryCategory", typeof(LibraryCategoryItem))]
public ArrayList LibraryCategories;

I observe there was a consistent typo in the target XML you've requested
(it
says LibraryCatGEory instead of LibraryCatEGory). If that is intentional,
then
use [XmlArrayItem("LibraryCatgeory", typeof(LibraryCategoryItem))] here
instead.
In addition, I have class which defines the LibraryCategory item:

public class LibraryCategoryItem
{
public string LibraryCategory;
}


Further, to prevent the LibraryCategory field from being wrapped in an
element itself you must make it a text node with the following attribute,

[XmlText( )]
public string LibraryCategory;
Derek Harmon


Thanks very much for a great, timely response.
Nov 12 '05 #3

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

Similar topics

3
3061
by: Franz | last post by:
Let me describe the flow of my program first. 1. Deserialize data from xml file. 2. Addition of "PersonType" class to the AllPersonalData. 3. Serialize data back to the xml file. My question is...
16
9490
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
2205
by: Ice | last post by:
All - I'm pretty comfortable with simple XML serialization of objects. However I observed something the other day and I wanted to know if I solved it the right way. Basically if I have a...
4
8690
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
0
7281
by: Just D. | last post by:
There is an interesting article - http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=542&printer=t It shows how to serialize the ArrayList of identical objects. I did it a year...
3
2441
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type...
1
4367
by: Eric Porter | last post by:
Help! Below is some code for a Web Service which has two methods, First() and Second(). However, when the code is run, whichever of the two methods appears second in the source fails with...
8
2451
by: jamie | last post by:
Here's a class I'm working with public class BatchHeader { public string ScaleSite; public string FromScaleDate;
2
1214
by: dfontanesi | last post by:
I'm trying to serialize a class that contains an ArrayList...something like this: public class Units { private ArrayList _units; private string _description;
0
7098
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
7298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.