Click here to Skip to main content
15,880,608 members
Articles / Desktop Programming / Windows Forms

An XML Schema Definition (XSD) Editor and Strongly-Typed Configuration Class Generator

Rate me:
Please Sign up or sign in to vote.
4.82/5 (6 votes)
20 Jul 2009CPOL5 min read 39.3K   2.5K   28  
An editor capable of producing commmon XSD documents and generating strongly-typed configuration class corresponding to the XML schema (XSD) file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConfigClassGenDemo
{
    class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            Program main = new Program();
            main.Run();
        }

        AppConfig config;

        private void Run()
        {
            try
            {
                config = AppConfig.GetConfig("AppConfig");

                Console.Out.WriteLine(string.Format("Client ID: {0}", config.ClientID));
                Console.Out.WriteLine(string.Format("Client Name: {0}", config.ClientName));

                Console.Out.WriteLine();
                Console.Out.WriteLine(string.Format("Selected Province: {0}", config.ProvinceCollections[config.ProvinceCollections.GetIndexByAbbreviation("ON")].Name));

                Console.Out.WriteLine();
                foreach (AppConfig.ProvinceCollection.Province p in config.ProvinceCollections)
                {
                    Console.Out.WriteLine(string.Format("Province: {0} - {1} - {2}", p.Abbreviation, p.Name, p.Population));
                }

                Console.Out.WriteLine();
                foreach (AppConfig.ContactCollection.Contact c in config.ContactCollections)
                {
                    Console.Out.WriteLine(string.Format("Contact: {0} - {1} - {2} - {3} - {4}",
                        c.Name,
                        c.AddressField.City, c.AddressField.Province,
                        config.ProvinceCollections[config.ProvinceCollections.GetIndexByAbbreviation(c.AddressField.Province)].Name,
                        config.ProvinceCollections[config.ProvinceCollections.GetIndexByAbbreviation(c.AddressField.Province)].Population,
                        c.AddressField.StreetAddress));
                }

                Console.In.ReadLine();
            }
            catch (Exception ex)
            {
                // handle exception

                throw ex;
            }

        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) ThinData
Canada Canada
Song is a senior .NET Developer specialized on both Web and Windows applications. He is an MCTS (Microsoft Certified Technology Specialist) for Windows Applications, Web Applications and Distributed Applications.

He currently lives in Toronto and likes to travel.

You may contact Song through his email: song_gao@hotmail.com

Comments and Discussions