[Mono-list] XML deserialization - HELP!!!!!

Paul paul at all-the-johnsons.co.uk
Mon May 24 18:21:09 EDT 2010


As part of a much larger project, I'm doing a simple proof of concept
work. Basically, the code I have loads in an XML file and generates a
winform on the fly.

The code is at a very early stage, but I've hit a problem. It compiles,
it runs, it just completely fails to load in the XML file (well,
something happens, but not what I'm after which should be a winform
generated based on the XML file.

Current code looks like this

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;

namespace form_from_xml 
    public class xmlhandler : Form
        public void loaddesign()
            FormData f;
            f = null;

                string path_env =
Path.GetDirectoryName(Application.ExecutablePath) +
                XmlSerializer s = new XmlSerializer(typeof(FormData));
                TextReader r = new StreamReader(path_env +
                f = (FormData)s.Deserialize(r);
            catch (System.IO.FileNotFoundException)
                MessageBox.Show("Unable to find the form file", "File
not found", MessageBoxButtons.OK);
            catch (System.InvalidOperationException e)
                MessageBox.Show(e.ToString(), "Error",
            winformgen wf = new winformgen();

    public class winformgen : Form
        public void makeform(FormData f)
            Form form1 = new Form();
            Label label1 = new Label();
            label1.Text = f.elements[0].text;
            label1.Location = new Point(f.elements[0].xpos,
            form1.FormBorderStyle = FormBorderStyle.FixedDialog;
            form1.MaximizeBox = false;
            form1.MinimizeBox = false;
            form1.StartPosition = FormStartPosition.CenterScreen;
            form1.Width = f.elements[0].winxs;
            form1.Height = f.elements[0].winys;

    public class FormData
        private ArrayList formData;

        public FormData()
            formData = new ArrayList();

        public Elements[] elements
                Elements[] elements = new Elements[formData.Count];
                return elements;
                if (value == null)
                Elements[] elements = (Elements[])value;
                foreach (Elements element in elements)
    public class Elements
        public string name;
        public int winxs;
        public int winys;
        public string type;
        public int xpos;
        public int ypos;
        public bool external;
        public string externalplace;
        public string text;
        public bool questions;
        public string qtype;
        public int numberqs;
        public string ansfile;
        public int backlink;
        public int forwardlink;

        public Elements()

        public Elements(string fn, int wx, int wy, string t, int x, int
y, bool ext, string extpl, string te, bool q, 
            string qt, int num, string ans, int back, int end)
            name = fn;
            winxs = wx;
            winys = wy;
            type = t;
            xpos = x;
            ypos = y;
            external = ext;
            externalplace = extpl;
            text = te;
            questions = q;
            qtype = qt;
            numberqs = num;
            ansfile = ans;
            backlink = back;
            forwardlink = end;

With the XML file

<?xml version="1.0" encoding="utf-8"?>
		<formname>Test Window</formname>
		<text>Hello world!</text>

(to get it to work, a quick winform button which generates a new
instance of xmlhandler then call the new instance)

I can't for the life of me see why it's not reading in. The only thing I
can think of is that there is a problem in the XML file somewhere...

Any help would be greatly appreciated :-)


Biggles was quietly reading his favourite book when Algy burst through
the door. Distracted for a moment, Biggles surveyed what had happened
and turned a page. "Algy old man" he said, clearing his throat, "use the
handle next time..." - Taken from "Biggles combs his Hair"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
Url : http://lists.ximian.com/pipermail/mono-list/attachments/20100524/724b9f4f/attachment-0001.bin 

More information about the Mono-list mailing list