I'm trying to serialize the object below and get the following error when creating the xml file.
XML document must have a top level element. Error processing resource
It works when there is just one instance in the collection. Can anyone help me with this?
[Serializable]
public class Processes
{
string pvtProcessesName = "";
List
public Processes()
{
}
public string ProcessesName
{
get { return pvtProcessesName; }
set { pvtProcessesName = value; }
}
public List
{
get { return pvtPros; }
set { pvtPros = value; }
}
public void Add(ProcessAttribute pAtt)
{
pvtPros.Add(pAtt);
}
}
The above object has a collection of the below object
[Serializable]
public class ProcessAttribute
{
string pvtName = "";
List
public ProcessAttribute()
{
}
public string ProcessName
{
get { return pvtName; }
set { pvtName = value; }
}
public List
{
get { return pvtNodes; }
set { pvtNodes = value; }
}
public void Add(NodeAttributes nd)
{
pvtNodes.Add(nd);
}
}
NodeAttributes is a class with variables with get and set methods.
How can I solve the problem
Jan MontanoPosted Jun 1, 2007, 3:20 AM
This is what I've got so far. No errors yet
private void button5_Click(object sender, EventArgs e)
{
thavsPosted Jun 1, 2007, 2:11 AM
public
class NodeAttributes{
// private members string pvt_strProcessName = "Process Name"; string pvt_strName = "Node Name"; string pvt_Level = "Level"; string pvt_Group = "Group"; string pvt_Location = "Location"; string pvt_strUserAlloc = "User1"; string pvt_Form = "Form1"; string pvt_ActionReq = "Action"; string pvt_strOption = "Option1"; string pvt_strReminder = "0"; string pvt_strMaximum = "0"; bool pvt_strEscalate = true; bool pvt_strLogStats = true; Node pvtNode = null; // public accessors[
CategoryAttribute("Description"), DefaultValueAttribute("Process"), ReadOnly(true)] public string ProcessName{ get { return pvt_strProcessName; } set { pvt_strProcessName = value; }}
[
CategoryAttribute("Description"),DefaultValueAttribute("Node Name")] public string Name{ get { return pvt_strName; } set { pvt_strName = value; }}[
CategoryAttribute("Task Allocation"), TypeConverter(typeof(Levels))] public string Level{ get { return pvt_Level; } set { pvt_Level = value; }}[
CategoryAttribute("Task Allocation"), TypeConverter(typeof(Groups))] public string Group{ get { return pvt_Group; } set { pvt_Group = value; }}[
CategoryAttribute("Task Allocation"), TypeConverter(typeof(Locations))] public string Location{ get { return pvt_Location; } set { pvt_Location = value; }}[
CategoryAttribute("Allocation Type"),DefaultValueAttribute("First User")] public string UserAlloc{ get { return pvt_strUserAlloc; } set { pvt_strUserAlloc = value; }}[
CategoryAttribute("Visual Options"), TypeConverter(typeof(Forms))] public string Form{ get { return pvt_Form; } set { pvt_Form = value; }}[
CategoryAttribute("Visual Options"), TypeConverter(typeof(Actions ))] public string ActionReq{ get { return pvt_ActionReq; } set { pvt_ActionReq = value; }}[
CategoryAttribute("Visual Options"), TypeConverter(typeof(Options))] public string Option{ get { return pvt_strOption; } set { pvt_strOption = value; }}[
CategoryAttribute("Non-Action"),DefaultValueAttribute("Reminder")] public string Reminder{ get { return pvt_strReminder; } set { pvt_strReminder = value; }}[
CategoryAttribute("Non-Action"),DefaultValueAttribute("Maximum")] public string Maximum{ get { return pvt_strMaximum; } set { pvt_strMaximum = value; }} public bool Escalate{ get { return pvt_strEscalate; } set { pvt_strEscalate = value; }} public bool LogStats{ get { return pvt_strLogStats; } set { pvt_strLogStats = value; }} public Node PNode{ get { return pvtNode; } set { pvtNode = value; }}
public class Groups : StringConverter{
private static ArrayList groups = new ArrayList(); private string[] gps = new string[10]; public void GetGroups(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("Select * from Groups", conn); SqlDataReader rd = null;conn.Open();
groups.Clear();
rd = cmd.ExecuteReader();
int i = 0; int gID = 0; string gDesc = ""; while (rd.Read()){
gID =
Convert.ToInt32(rd.GetValue(0));gDesc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(gID, gDesc);groups.Add(d);
gps[i] = gDesc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetGroups();
return new StandardValuesCollection(gps);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Levels : StringConverter{
private static ArrayList levels = new ArrayList(); private string[] ls = new string[10]; public void GetLevels(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("Select * from Levels", conn); SqlDataReader rd = null;conn.Open();
rd = cmd.ExecuteReader();
levels.Clear();
int i = 0; int ID = 0; string Desc = ""; while (rd.Read()){
ID =
Convert.ToInt32(rd.GetValue(0));Desc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(Convert.ToInt32(rd.GetValue(0)), Convert.ToString(rd.GetValue(1)));levels.Add(d);
ls[i] = Desc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetLevels();
return new StandardValuesCollection(ls);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Locations : StringConverter{
private static ArrayList locations = new ArrayList(); private string[] locs = new string[10]; public void GetLocations(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("SELECT LocationID,Description FROM Locations", conn); SqlDataReader rd = null;conn.Open();
rd = cmd.ExecuteReader();
locations.Clear();
int i = 0; int ID = 0; string Desc = ""; while (rd.Read()){
ID =
Convert.ToInt32(rd.GetValue(0));Desc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(Convert.ToInt32(rd.GetValue(0)), Convert.ToString(rd.GetValue(1)));locations.Add(d);
locs[i] = Desc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetLocations();
return new StandardValuesCollection(locs);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Forms : StringConverter{
private static ArrayList forms = new ArrayList(); private string[] frms = new string[10]; public void GetForms(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("Select * from GetForms", conn); SqlDataReader rd = null;conn.Open();
rd = cmd.ExecuteReader();
forms.Clear();
int i = 0; int ID = 0; string Desc = ""; while (rd.Read()){
ID =
Convert.ToInt32(rd.GetValue(0));Desc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(Convert.ToInt32(rd.GetValue(0)), Convert.ToString(rd.GetValue(1)));forms.Add(d);
frms[i] = Desc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetForms();
return new StandardValuesCollection(frms);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Actions : StringConverter{
private static ArrayList actions = new ArrayList(); private string[] acts = new string[10]; public void GetActions(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("Select * from GetActions where REQ=1", conn); SqlDataReader rd = null;conn.Open();
rd = cmd.ExecuteReader();
actions.Clear();
int i = 0; int ID = 0; string Desc = ""; while (rd.Read()){
ID =
Convert.ToInt32(rd.GetValue(0));Desc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(Convert.ToInt32(rd.GetValue(0)), Convert.ToString(rd.GetValue(1)));actions.Add(d);
acts[i] = Desc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetActions();
return new StandardValuesCollection(acts);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Options : StringConverter{
private static ArrayList options = new ArrayList(); private string[] opts = new string[10]; public void GetOptions(){
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["Connection"].ToString()); SqlCommand cmd = new SqlCommand("Select * from GetOptionGroups", conn); SqlDataReader rd = null;conn.Open();
rd = cmd.ExecuteReader();
options.Clear();
int i = 0; int ID = 0; string Desc = ""; while (rd.Read()){
ID =
Convert.ToInt32(rd.GetValue(0));Desc =
Convert.ToString(rd.GetValue(1)); Data d = new Data(Convert.ToInt32(rd.GetValue(0)), Convert.ToString(rd.GetValue(1)));options.Add(d);
opts[i] = Desc;
i += 1;
}
rd.Close();
conn.Close();
}
public override bool GetStandardValuesSupported( ITypeDescriptorContext context){
return true;}
public override StandardValuesCollectionGetStandardValues(
ITypeDescriptorContext context){
GetOptions();
return new StandardValuesCollection(opts);}
public override bool GetStandardValuesExclusive( ITypeDescriptorContext context){
return false;}
}
public class Data{
private int id = 0; private string decription = ""; public Data(int i, string d){
id = i;
decription = d;
}
public int ID { get { return id; } set { id = value; } } public string Description { get { return decription; } set { decription = value; } }}
Jan MontanoPosted May 31, 2007, 11:09 PM