473,769 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML deserialization problem

Hi all,

i have a problem with a class which has several subclasses embedded when
trying to deserialize it.

Serializing works just fine. The xml is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" ProjectName="Te st
Project">
<CreationDate>2 005-03-22T16:07:50.355 6672+01:00</CreationDate>
<XmlSourceDocum ents>
<XmlSourceDocum ent>
<CreationDate>2 005-03-22T16:07:50.355 6672+01:00</CreationDate>
<DocumentName>D oc 1</DocumentName>
</XmlSourceDocume nt>
<XmlSourceDocum ent>
<CreationDate>2 005-03-22T16:07:50.355 6672+01:00</CreationDate>
<DocumentName>D oc 1</DocumentName>
</XmlSourceDocume nt>
<XmlSourceDocum ent>
<CreationDate>2 005-03-22T16:07:50.355 6672+01:00</CreationDate>
<DocumentName>D oc 1</DocumentName>
</XmlSourceDocume nt>
</XmlSourceDocume nts>
</Project>

The underlying class looks like this:

{
public class Project
{
public Project()
{
m_alSourceDocum ents = new ArrayList();
}

private ArrayList m_alSourceDocum ents;
private string m_sProjectName;
private DateTime m_dtCreationDat e;
private StylesheetRepos itoryItem m_oStylesheetRe positoryItem;

public StylesheetRepos itoryItem StyleSheet
{
get { return m_oStylesheetRe positoryItem; }
set { m_oStylesheetRe positoryItem = value; }
}

public DateTime CreationDate
{
get { return m_dtCreationDat e; }
set { m_dtCreationDat e = value; }
}

public string ProjectName
{
get { return m_sProjectName; }
set { m_sProjectName = value; }
}

public int Add(XmlSourceDo cument in_oSourceDoc)
{
return m_alSourceDocum ents.Add(in_oSo urceDoc);
}

public void AddRange(XmlSou rceDocument[] in_arSourceDocR ange)
{
m_alSourceDocum ents.AddRange(i n_arSourceDocRa nge);
}

public void Remove(XmlSourc eDocument in_oSourceDocum ent)
{
m_alSourceDocum ents.Remove(in_ oSourceDocument );
}

public void RemoveAt(int index)
{
m_alSourceDocum ents.RemoveAt(i ndex);
}

public void Clear()
{
m_alSourceDocum ents.Clear();
}

public void Insert(int index, XmlSourceDocume nt in_oSourceDocum ent)
{
m_alSourceDocum ents.Insert(ind ex,in_oSourceDo cument);
}

public int Count
{
get { return m_alSourceDocum ents.Count; }
}

public XmlSourceDocume nt[] XmlSourceDocume nts
{
get { return
(XmlSourceDocum ent[])m_alSourceDocu ments.ToArray(t ypeof(XmlSource Document));
}
set {}
}

public void SaveProject(str ing path)
{
lock(path)
{
if(File.Exists( path))
File.Delete(pat h);
XmlSerializer xsr = new XmlSerializer(t ypeof(Project)) ;
FileStream fs = new
FileStream(path ,FileMode.Creat e,FileAccess.Wr ite,FileShare.R ead);
XmlTextWriter xtw = new XmlTextWriter(f s,System.Text.E ncoding.UTF8);
xtw.Formatting = Formatting.Inde nted;
try
{
xsr.Serialize(x tw,this);
}
catch(Exception ex)
{
}
finally
{
xtw.Close();
}
}
}

public static Project LoadProject(str ing path)
{
XmlSerializer xsr = new XmlSerializer(t ypeof(Project)) ;
FileStream fs = File.OpenRead(p ath);
Project cs = (Project)xsr.De serialize(fs);
fs.Close();
return cs;
}
}
}

The problem is that when i try to deserialize the xml file the
XmlSourceDocume nt Array has the length of 0. So the XmlSourceDocume nt
nodes beeing not deserialized.

Can someone help with this? I somehow suspect my approach using an
ArrayList beeing not correct.

Thanks in advance,

David
Nov 17 '05 #1
0 1464

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

Similar topics

3
1662
by: TEK | last post by:
There seems to be a bug when deserialization some classes in the .NET framework. If you try to deserialize a class that has a base class that holds a struct with a member that is implementing the ICollection interface, this causes the deserialization to fail. In my case this is a huge problem, and any suggestion for a workaround would be happily received. A small example of a set of classes that reproduces the problem is included
2
2334
by: Meta-Meta | last post by:
Hi, I'm trying to deserialize a VC++ .NET class and am stumped by the following problem : In order to create the XmlSerializer you need to pass the type of the object being created. The doc shows the example in C# (no C++ available) : >> MySerializableClass myObject;
2
3825
by: Snowman | last post by:
Suppose I have a RootObject which holds a collection of other objects. The other objects have a property (Parent) which refers back to the "parent" collection (b.t.w. my collection is based on CollectionBase), in similar fashion as the object models of MS Office. I want to serialize this object graph (with RootObject as the xml document element) without Parent property serialized, this may be done by adding XmlIgnoreAttribute on the...
3
9796
by: Amadelle | last post by:
Hi all and thanks in advance for your help, I am having problems deserializing an object which seems to be serializing just fine. I save the byte array of the serialized object in the database (when I check the database the field that holds the binary data seems populated), but when I want to deserialize this same byte array the application fails and gives me the following error: Binary stream does not contain a valid BinaryHeader, 0...
3
2069
by: AnkitAsDeveloper [Ankit] | last post by:
Hi i am serializing a 'ref struct' object as follows : private: void Seri( String ^path, Object^ obj ) { FileStream^ fileStrm ; try { //Serialize entire object into Binary stream
3
9795
by: parrot toes | last post by:
Summary: I have been trying to make requests of a web service provided by Axis using a dotnet client with code generated by wsdl.exe and have been getting exceptions when trying to process the response. As a result of seraching news groups I guessed that the SOAP response defines an array element in a way that causes the dotnet deserialization routines to put the content in a generic object array (object) BUT the content is supposed to...
1
3751
by: parrot toes | last post by:
I tried to post this question before, but there was an error when posting. I case it did get posted and in order to avoid duplication, I'll just repost a summary. I have written a dotnet client that accesses a Axis provided web service. The client uses the code generated, using wsdl.exe, from the wsdl file provided by the web service provider. The web response has the following schema (roughly):
5
2294
by: Greg Allen | last post by:
I am consuming a web service and using the generated Reference.cs to access the service and the objects associated with it. I have run into a problem where some inherited classes are not being deserialized. I have verified that the XML being returned by the service contains the tags I am expecting, but they don't show up in the resulting object. Here's the relevant portion of the Reference.cs file: public class FormSection {
3
4999
by: John Glover | last post by:
To whoever can help, I've been having a problem with XML deserialization lately. I needed to serialize and deserialze two objects which inherited from Hashtable. Because IDictionary implementations cannot be serialized, I had to take matters into my own hands by implementing a wrapper over the Hashtable which implemted IXmlSerializable. I called it XmlHashtable. It has, among other convenience methods, a method
7
16167
by: Andrew | last post by:
Hi, I am using DataContractJsonSerializer to deserialize JSON string in C# objects but I am having a problem. Suppose I have a class: class Item { public ItemId Id { get; set; }
0
9583
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10210
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
10039
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
9990
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
9860
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
8869
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
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3955
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
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.