简体   繁体   中英

How to create an XML file of an object

I am working on a word recognition in automata, and for the exchange of information I need to create an XML file of my object.

already use the library using System.Xml.Serialization;

[Serializable]
    class Automata
    {
        public List<int> estado_Q { get; set; }
        public List<char> alfabeto_X { get; set; }
        public List<Transicion> ftrans_t { get; set; }
        public int estadoInicio_qo { get; set; }
        public List<int> estadosFinales_F { get; set; }

        public Automata(List<int> Q, List<char> X, List<Transicion> T, int qo, List<int> F)
        {
            estado_Q = Q;
            alfabeto_X = X;
            ftrans_t = T;
            estadoInicio_qo = qo;
            estadosFinales_F = F;

        }

    }`
[Serializable]
    class Transicion
    {
        public int fromEstado { get; set; }
        public char leeyendo { get; set; }
        public int untilEstado { get; set; }


        public Transicion(int iEstado, char leer, int fEstado)
        {
            fromEstado = iEstado;
            leeyendo = leer;
            untilEstado = fEstado;
        }
    }
static void Main(string[] args)
        {
                     Clases.Automata au = new Clases.Automata();

            var automatalista = new Automata();
            XmlSerializer serializer = new XmlSerializer(typeof(List<Automata>));

            using (TextWriter writer = new StreamWriter("C:\\Users\\user\\Downloads\\Temp\\File.xml"))
            {
                serializer.Serialize(writer, automatalista);
            }

        }

I want you to generate an XML file, but I get an error.`

System.InvalidOperationException: 'Create Xml Object.Program no es accesible por el nivel de protección. Sólo se pueden procesar tipos públicos.'

You need to make the types public. EG

public class Automata . . .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM