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

help with serializing

hi, i am trying to serialize the following class :

namespace MyNameSpace
{
[System.Xml.Serialization.XmlRootAttribute("Station Data", Namespace="",
IsNullable=false)]
public class StationData
{
[System.Xml.Serialization.XmlElementAttribute("Stat ion")]
public Station[] Station;
}

public class Station
{
public int ID;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IDSpecified;

public string Name;

[System.Xml.Serialization.XmlElementAttribute("Game Sets")]
public GameSetData[] GameSets;
}

public class GameSetData
{
public int ID;

[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool IDSpecified;

public string Name;
}
}
to the following XML:

<?xml version="1.0" encoding="utf-8" ?>
<StationData>
<Station>
<ID>-1</ID>
<Name>ALL</Name>
<GameSets>
<ID>0</ID>
<Name>x</Name>
</GameSets>
<GameSets>
<ID>2</ID>
<Name>xx</Name>
</GameSets>
<GameSets>
<ID>4</ID>
<Name>xxx</Name>
</GameSets>
<GameSets>
<ID>6</ID>
<Name>xxxx</Name>
</GameSets>
<GameSets>
<ID>8</ID>
<Name>xxxxx</Name>
</GameSets>
</Station>
<Station>
<ID>1</ID>
<Name>xxxxxxx</Name>
<GameSets>
<ID>6</ID>
<Name>xxxx</Name>
</GameSets>
</Station>
<Station>
<ID>2</ID>
<Name>xxxxxxxx</Name>
<GameSets>
<id>4</id>
<Name>xxx</Name>
</GameSets>
<GameSets>
<id>0</id>
<Name>x</Name>
</GameSets>
</Station>
<Station>
<ID>3</ID>
<Name>xxxxxxxxxx</Name>
<GameSets>
<ID>2</ID>
<Name>xx</Name>
</GameSets>
<GameSets>
<ID>8</ID>
<Name>xxxxx</Name>
</GameSets>
</Station>
</StationData>

with the following code:
ArrayList newStations = new ArrayList();
for(int j=0; j< m_StationData.Station.Length; j++)
{
// do some stuff here
}
Station[] NewStations = newStations.ToArray(typeof(Station)) as
Station[];

// write stationdata to XML file
string fileName = @"c:/logs/swmstations_new.xml";
XmlSerializer serializer = new XmlSerializer(typeof(Station),
"StationData");
TextWriter textwriter = new StreamWriter(fileName);
serializer.Serialize(textwriter, NewStations);
textwriter.Close();


it throws an inner exception of "the specified cast is not valid" - i
have tried various other permutations of the new XMLSerializer() and
they all throw an exception.

mind you, the xml document deserializes into the class without a
problem. xsd.exe generated the class file for me.

am i missing something here? or, is there an easy way to cast my
Station[] array as a stationdata object that will write to the xml
cleanly?

Nov 16 '05 #1
0 825

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

Similar topics

2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
0
by: Ante Smolcic | last post by:
Hi all, I have an ArrayList that contains items of type A. I declared the XmlArrayItem atribute for that type. Now I have an derived type B (from A) also contained in the ArrayList but I get...
1
by: Ivo Bronsveld | last post by:
All, I have quite a challenging task ahead of me. I need to write an object model (for code access) based on a schema, which cannot be made into a dataset because of it's complexity. So I...
10
by: copx | last post by:
I want to save a struct to disk.... as plain text. At the moment I do it with a function that just writes the data using fprintf. I mean like this: fprintf(fp, "%d %d", my_struct.a, my_struct.b)...
5
by: Alfonso Morra | last post by:
Hi, I am writing a messaging library which will allow me to send a generic message structure with custom "payloads". In many cases, a message must store a non-linear data structure (i.e....
6
by: Rein Petersen | last post by:
Hi Folks! Here's a strange behaviour: Without a properties SET accessor (see code below), the property will not serialize. public class myObject {
4
by: Jason Shohet | last post by:
We are thinking of serializing an object & passing it toseveral functions on web service. This will happen about 35 times as the page loads. The class has about 20 attributes. We're not sure...
2
by: Simon | last post by:
I'm developing a new application and want to use serialization as a way to save my data. But as I add new variables to my classes, how will serializing cope with that? For example, suppose I have...
15
by: Cesar Ronchese | last post by:
Hi, I built the sample code showing the problem with dates when viewed at different machines, different Time Zones and transported via Remoting. The zip can be downloaded here: ...
12
by: Cagdas Ozgenc | last post by:
Greetings, When directly serializing C++ structures to a file with the standard library functions giving the address of the data and length of structure using the sizeof operator, do I risk...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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
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
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...
0
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...

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.