473,326 Members | 2,136 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,326 software developers and data experts.

Serialize more than one array

Hello,

I have made a little test application and needs some help.
I have two classes with hash tables which I want to serialize inside one xml
file.

My question is if someone can make the code complete? (loading and saving)
- I have made some starting points.
- The // comment tags says where to do "something".
- What the "something" means I don't know... but I have tried...

I have copy paste the code of this console application under this message.
If you have any questions please ask me! Because I want to make a working
testapplication.
With some help it must be no problem! (I hope so)

Many thanks!
Arjen


using System;

using System.Collections;

using System.IO;

using System.Xml;

using System.Xml.Serialization;

namespace TestApplication

{

/// <summary>

/// Summary description for Class1.

/// </summary>

class TestApplication

{

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void Main(string[] args)

{

// LoadXML

loadXML();

// Add some persons and animals

// SaveXML

saveXML();

}

static void loadXML() {

XmlSerializer x = new XmlSerializer( typeof(Container[]) );

FileStream fs = null;

try {

fs = new FileStream( "data.xml", FileMode.Open );

XmlReader reader = new XmlTextReader( fs );

Container[] container = (Container[]) x.Deserialize( reader );

//

}

catch( FileNotFoundException ) {

}

finally {

if ( fs != null ) fs.Close();

}

}

static void saveXML() {

//

}

}

public class Container {
public Container() {

// I want to load/save the Hashtables of person and animals.

// inside one xml file

// Person persons = new Person();

// Animal animals = new Animal();

}

}

public class Person {

private Hashtable myTable = new Hashtable();

private string _name;
public string Name {

get {

return _name;

}

set {

_name = value;

}

}

public void AddPeron ( Person person ) {

try {

myTable.Add( person.GetHashCode(), person );

}

catch( ArgumentException ) {

}

}

public Person() {

}

}

public class Animal {

private Hashtable myTable = new Hashtable();

private string _name;
public string Name {

get {

return _name;

}

set {

_name = value;

}

}

public void AddAnimal ( Animal animal ) {

try {

myTable.Add( animal.GetHashCode(), animal );

}

catch( ArgumentException ) {

}

}

public Animal() {

}

}

}


Nov 15 '05 #1
0 1053

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

Similar topics

8
by: John Smith | last post by:
Hi, I am using a custom Session Handler. session_set_save_handler is working well. But i want to read the data direct from the database. My problem: php don't uses the standard serialize...
2
by: Andrew | last post by:
Some have suggested that using serialize() and unserialize is faster than reading/writing an array to disk as a simple text file using $array = file('numbers.txt'); Can anyone justify this? ...
5
by: Brian Reed | last post by:
I have a class that I want to serialize to an XML string. I want the XML to serialize to utf-8 encoding. When I serialize to an XML file, the data looks great. When I try to serialize to a String...
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: Arjen | last post by:
Hello, I have an array "aPeople" with people objects which I serialize like this: XmlSerializer x = new XmlSerializer( typeof(People) ); TextWriter writer = new StreamWriter( "data.xml" );...
1
by: Marcin | last post by:
hi, I would like to ask how to serialize class with members like SqlParameter. I try to use BinaryFormatter. public class Example_Class { public SqlParameter sqlParam; public...
2
by: nick | last post by:
Is it recommended to serialize a custom object when putting it in session? I have a User object with properties ID, FirstName, LastName, and an array of Permissions which I would like to keep in...
2
by: Joe | last post by:
Hi I have a Generics List in a PropertyGrid I am able to Serialize it to XML but when I try to deserialize back to the class of the PropertyGrid The Constructor doesn't seem to fire to reload...
6
by: Paez | last post by:
Hello there. My teacher asked me to do a job and I don't know how.. This is the scenario: I must create a client/server application. The server application is a c# web server and the client...
3
by: Andrew Robinson | last post by:
I am using the folllowing code to serialize a object to a byte array (byte). It works fine, but my resulting array is size is being rounded up to the next largest 32768 boundary. How can I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.