473,804 Members | 3,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "InvalidOperati onException: The type
System.Xml.XmlE lement 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.El ement, "record", "");
oNode1.InnerTex t = "abc";

oArr.Add(oNode1 );

XmlNode oNode2 = oXML.CreateNode
(XmlNodeType.El ement, "record", "");
oNode2.InnerTex t = "xyz";
oArr.Add(oNode2 );

MemoryStream oMem = new MemoryStream();

XmlSerializer xs = new XmlSerializer(t ypeof(ArrayList ));

xs.Serialize(oM em, oArr);

oMem.Position = 0;
ArrayList oresult = (ArrayList)xs.D eserialize(oMem );
Nov 11 '05 #1
0 3572

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

Similar topics

4
1451
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 80 chars or so, if that matters. I figured I'd set the attribute on the object and on the ArrayList and use standard Serialize() functions. This is just incredibly slow. Is that normal? Any other recommended approach? The function itself...
1
7044
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 LanguageName As String Public LanguageCode As String Public Active As Integer
2
2619
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 ArrayList is currently deserializing in the constructor. When is the correct time to serialize the ArrayList to XML? In C++ I would do this in the destructor. I see C# has a destructor, but I am unsure about all of this IDisposable, Finalize,...
14
14320
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
24733
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 s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
1
2825
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 Order and LineItem are marked with the <Serializable> attribute. When I attempt to serialize the class using this code: Dim xs As XmlSerializer = New XmlSerializer(GetType(Order)) Dim sw As New StringWriter()
5
8043
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 example of what I'd want to accomplish. Thanks Brad Example
17
1879
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
2488
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 myfeeds As New ArrayList myfeeds = <<method that populates arraylist with objects>> Dim BinFormatter As New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
0
9587
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
10588
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...
0
10340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10324
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
10085
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
9161
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...
0
6857
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
4302
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
3827
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.