473,657 Members | 2,358 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:

<LibraryCategor ies>
<LibraryCatgeor y>1</LibraryCatgeory >
<LibraryCatgeor y>2</LibraryCatgeory >
<LibraryCatgeor y>3</LibraryCatgeory >
</LibraryCategori es>

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

[XmlElement(Type = typeof(LibraryC ategoryItem))]
public ArrayList LibraryCategori es;

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

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

<LibraryCategor ies>
<LibraryCatgeor y>1</LibraryCatgeory >
</LibraryCategori es>
<LibraryCategor ies>
<LibraryCatgeor y>2</LibraryCatgeory >
</LibraryCategori es>
<LibraryCategor ies>
<LibraryCatgeor y>3</LibraryCatgeory >
</LibraryCategori es>
What attributes do I need to place on the LibraryCategori es and/or the
LibraryCategory Item class to enforce the desired XML?
Nov 12 '05 #1
2 1198
"Codex Twin" <co***@gmail.co m> wrote in message news:42******** *************** @ptn-nntp-reader01.plus.n et...
My class has a public property called LibraryCategori es, of type ArrayList:

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

[XmlArray("Libra ryCategories")]
[XmlArrayItem("L ibraryCategory" , typeof(LibraryC ategoryItem))]
public ArrayList LibraryCategori es;

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("L ibraryCatgeory" , typeof(LibraryC ategoryItem))] here
instead.
In addition, I have class which defines the LibraryCategory item:

public class LibraryCategory Item
{
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******** ******@TK2MSFTN GP10.phx.gbl...
"Codex Twin" <co***@gmail.co m> wrote in message
news:42******** *************** @ptn-nntp-reader01.plus.n et...
My class has a public property called LibraryCategori es, of type
ArrayList:

[XmlElement(Type = typeof(LibraryC ategoryItem))]
public ArrayList LibraryCategori es;


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

[XmlArray("Libra ryCategories")]
[XmlArrayItem("L ibraryCategory" , typeof(LibraryC ategoryItem))]
public ArrayList LibraryCategori es;

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("L ibraryCatgeory" , typeof(LibraryC ategoryItem))] here
instead.
In addition, I have class which defines the LibraryCategory item:

public class LibraryCategory Item
{
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
3073
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 I have to use an array PersonType in the AllPersonalData class. But if I have to implement the "Addition of PersonalType" (i.e. the step 2), I have to use ArrayList instead of a fixed length array. I know that I can use the ArrayList as an...
16
9519
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> ....... ....... </ArrayOfClassname>
3
2224
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 string which contains a single xml node, I can serialize with this line of code: object = (object)serializer.Deserialize(new
4
8702
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 ds2 = (DataSet)formatter2.Deserialize(stream2); For the size of my DataSet, its taking 0.8 seconds to serialize and 2.3 seconds to deserialize.
0
7290
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 ago and it works fine. The question is if the ArrayList has a set of different objects of different type, every time different. We know what types should be involved, but we don't know what objects in what order and how many are used in the...
3
2451
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 System.Collections.Comparer has 1 members, number of members deserialized is 0. at System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.GetMemberTypes(String
1
4377
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 "System.InvalidCastException: Specified cast is not valid" in Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write5 _ArrayOfAnyType(Object o) of the temporary C# DLL that Web Service processing creates when serializing data.
8
2457
by: jamie | last post by:
Here's a class I'm working with public class BatchHeader { public string ScaleSite; public string FromScaleDate;
2
1223
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
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8838
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5638
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2740
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.