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

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="Test
Project">
<CreationDate>2005-03-22T16:07:50.3556672+01:00</CreationDate>
<XmlSourceDocuments>
<XmlSourceDocument>
<CreationDate>2005-03-22T16:07:50.3556672+01:00</CreationDate>
<DocumentName>Doc 1</DocumentName>
</XmlSourceDocument>
<XmlSourceDocument>
<CreationDate>2005-03-22T16:07:50.3556672+01:00</CreationDate>
<DocumentName>Doc 1</DocumentName>
</XmlSourceDocument>
<XmlSourceDocument>
<CreationDate>2005-03-22T16:07:50.3556672+01:00</CreationDate>
<DocumentName>Doc 1</DocumentName>
</XmlSourceDocument>
</XmlSourceDocuments>
</Project>

The underlying class looks like this:

{
public class Project
{
public Project()
{
m_alSourceDocuments = new ArrayList();
}

private ArrayList m_alSourceDocuments;
private string m_sProjectName;
private DateTime m_dtCreationDate;
private StylesheetRepositoryItem m_oStylesheetRepositoryItem;

public StylesheetRepositoryItem StyleSheet
{
get { return m_oStylesheetRepositoryItem; }
set { m_oStylesheetRepositoryItem = value; }
}

public DateTime CreationDate
{
get { return m_dtCreationDate; }
set { m_dtCreationDate = value; }
}

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

public int Add(XmlSourceDocument in_oSourceDoc)
{
return m_alSourceDocuments.Add(in_oSourceDoc);
}

public void AddRange(XmlSourceDocument[] in_arSourceDocRange)
{
m_alSourceDocuments.AddRange(in_arSourceDocRange);
}

public void Remove(XmlSourceDocument in_oSourceDocument)
{
m_alSourceDocuments.Remove(in_oSourceDocument);
}

public void RemoveAt(int index)
{
m_alSourceDocuments.RemoveAt(index);
}

public void Clear()
{
m_alSourceDocuments.Clear();
}

public void Insert(int index, XmlSourceDocument in_oSourceDocument)
{
m_alSourceDocuments.Insert(index,in_oSourceDocumen t);
}

public int Count
{
get { return m_alSourceDocuments.Count; }
}

public XmlSourceDocument[] XmlSourceDocuments
{
get { return
(XmlSourceDocument[])m_alSourceDocuments.ToArray(typeof(XmlSourceDocum ent));
}
set {}
}

public void SaveProject(string path)
{
lock(path)
{
if(File.Exists(path))
File.Delete(path);
XmlSerializer xsr = new XmlSerializer(typeof(Project));
FileStream fs = new
FileStream(path,FileMode.Create,FileAccess.Write,F ileShare.Read);
XmlTextWriter xtw = new XmlTextWriter(fs,System.Text.Encoding.UTF8);
xtw.Formatting = Formatting.Indented;
try
{
xsr.Serialize(xtw,this);
}
catch(Exception ex)
{
}
finally
{
xtw.Close();
}
}
}

public static Project LoadProject(string path)
{
XmlSerializer xsr = new XmlSerializer(typeof(Project));
FileStream fs = File.OpenRead(path);
Project cs = (Project)xsr.Deserialize(fs);
fs.Close();
return cs;
}
}
}

The problem is that when i try to deserialize the xml file the
XmlSourceDocument Array has the length of 0. So the XmlSourceDocument
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 1442

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

Similar topics

3
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...
2
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...
2
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...
3
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...
3
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
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...
1
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...
5
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...
3
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...
7
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
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...
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
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,...
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
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...
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
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,...

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.