3
Answers

Error while creating XML Document : XML document must have a top level element

thavs

thavs

17y
7.3k
1

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<ProcessAttribute> pvtPros = new List<ProcessAttribute>(0);

        public Processes()
        {
           
        }

        public string ProcessesName
        {
            get { return pvtProcessesName; }
            set { pvtProcessesName = value; }
        }
       
        public List<ProcessAttribute> All_Processes
        {
            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<NodeAttributes> pvtNodes = new List<NodeAttributes>(0);

        public ProcessAttribute()
        {
           
        }

        public string ProcessName
        {
            get { return pvtName; }
            set { pvtName = value; }
        }

        public List<NodeAttributes> Nodes
        {
            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



Answers (3)