Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / XML

A cool utility to convert XML schemas to classes

Rate me:
Please Sign up or sign in to vote.
4.53/5 (7 votes)
9 Oct 2009CPOL4 min read 46.4K   14K   49  
A cool utility to convert XML schemas to classes.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.CodeDom;

namespace XMLtoClass
{
    public partial class addCommentWz : Form
    {
        CodeTypeMember member;

        public addCommentWz(ref CodeTypeMember cm)
        {
            InitializeComponent();
            member = cm;
            foreach (CodeCommentStatement comment in member.Comments)
            {
                
                if (comment.Comment.Text.Contains("summary"))
                {
                    string summary = comment.Comment.Text.Substring(comment.Comment.Text.IndexOf("<summary>"), comment.Comment.Text.IndexOf("</summary>") - comment.Comment.Text.IndexOf("<summary>"));
                    txtSummary.Text = summary.Replace("<summary>", "").Replace("</summary>","");
                }
                if (comment.Comment.Text.Contains("remarks"))
                {
                    if (comment.Comment.Text != "<remarks/>")
                    {
                        string remarks = comment.Comment.Text.Substring(comment.Comment.Text.IndexOf("<remarks>"), comment.Comment.Text.IndexOf("</remarks>") - comment.Comment.Text.IndexOf("<remarks>"));
                        txtRemarks.Text = remarks.Replace("<remarks>", "").Replace("</remarks>", "");
                    }
                }
            }
        }

        private void addCommentWz_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            StringBuilder sb = new StringBuilder();
            string s = "";
            CodeComment comment = new CodeComment();
            comment.DocComment = true;
            
            sb.AppendFormat("<summary>{0}</summary>",txtSummary.Text);
//            sb.Append("<summary>{0}</summary>", txtSummary.Text);
            sb.AppendFormat("<remarks>{0}</remarks>", txtRemarks.Text);
            comment.Text = sb.ToString();
            member.Comments.Clear();
            member.Comments.Add(new CodeCommentStatement(comment));

            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}

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
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions