473,382 Members | 1,362 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,382 software developers and data experts.

Serialize XmlNode in an ArrayList

Hi all,

When I try to use XmlSerializer to serialize an ArrayList
object which contains XmlNode objects, I got
the "InvalidOperationException: The type
System.Xml.XmlElement may not be used in this context."

I can serialize an ArrayList object with string value and
also an XmlNode object individually without problem. I
have no idea why these two together can't work.
Any advice will be appreciated. Thanks.

Here is the sample code I am testing on:

------------------------------------------------
ArrayList oArr = new ArrayList();
XmlDocument oXML = new XmlDocument();

XmlNode oNode1 = oXML.CreateNode
(XmlNodeType.Element, "record", "");
oNode1.InnerText = "abc";

oArr.Add(oNode1);

XmlNode oNode2 = oXML.CreateNode
(XmlNodeType.Element, "record", "");
oNode2.InnerText = "xyz";
oArr.Add(oNode2);

MemoryStream oMem = new MemoryStream();

XmlSerializer xs = new XmlSerializer(typeof(ArrayList));

xs.Serialize(oMem, oArr);

oMem.Position = 0;
ArrayList oresult = (ArrayList)xs.Deserialize(oMem);
Nov 11 '05 #1
0 3528

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

Similar topics

4
by: _BNC | last post by:
I've got an ArrayList of objects that I'd like to save/retrieve as quickly as possible. Each item in the arraylist is an object with about 50 variable-length strings; many zero-length, some about...
1
by: Jonah Olsson | last post by:
Hello guys, Is there any way to serialize the following? Or do I need to create a new class called Languages that inherits Language? <Serializable()> _ Public Class Language Public...
2
by: Trevor Balcom | last post by:
I have a class which has a member variable of the type System.ArrayList. I plan on having the ArrayList serialize/deserialize itself to/from XML. I have worked out the code to do this and have the...
14
by: vince | last post by:
Can I add (append) to an xml file that already contains a serialized object, and be able to deserialize to either or both objects from the same file...??? How is this done...?? thanks, vince
5
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream...
1
by: Craig Buchanan | last post by:
I am trying to serialize a class called Order to the ViewState. Order has one property called LineItems, which is an ArrayList. The ArrayList holds instances of a class named LineItem. Bother...
5
by: Brad | last post by:
I would like to serialize an arraylist of objects to xml so I can store the xml in a database column. How would I code the serializing and deserializing? Below is a (overly) simple, incomplete...
17
by: Peter | last post by:
How would would you deserialize this example below? Imports System Imports System.Collections Imports System.IO Imports System.Xml.Serialization Public Class App1 Shared Sub Main()
2
by: Derek Martin | last post by:
Hey list, I have an arraylist containing some objects that I want to serialize and send over the internet and then deserialize back into the arraylist of objects. What I have so far: Dim...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.