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