Click here to Skip to main content
12,400,183 members (54,092 online)
Click here to Skip to main content

Stats

122.5K views
4.4K downloads
61 bookmarked
Posted

WSDL and Schema Parser

, 25 Nov 2005
Modeling WSDL and XML schema on a TreeView control and generating XML document from XML schemas.
//Author contact: Thanh.Dao@gmx.net
using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;

using System.Drawing;
namespace WSDLParser
{
	public class MyRichText : RichTextBox
	{
		public bool IsEmpty=false;
		public static String [] keywords={																	   "anyURI",
											 "base64Binary",
											 "boolean",
											 "byte",
											 "date",
											 "dateTime",
											 "decimal",
											 "double",
											 "duration",
											 "ENTITIY",
											 "float",
											 "gDay",
											 "gMonth",
											 "gMonthDay",
											 "gYear",
											 "gYearMonth",
											 "hexBinary",
											 "ID",
											 "IDREF",
											 "integer",
											 "int",
											 "language",
											 "long",
											 "Name",
											 "NCName",
											 "negativeInteger",
											 "NMTOKEN",
											 "nonNegativeInteger",
											 "nonPositiveInteger",
											 "normalizedString",
											 "NOTATION",
											 "positiveInteger",
											 "QName",
											 "short",
											 "string",
											 "time",
											 "token",
											 "unsignedByte",
											 "unsignedInt",
											 "unsignedLong",
											 "unsignedShort",
											 "XmlSchemaElement",
											 "XmlSchemaAttribute"};
	
		public static String [] operators={"<","/",">","?"}
							;

	
		public MyRichText()
		{
			this.AllowDrop=true;
			MyInit();

		}

		private void MyInit()
		{
			
		}


		protected override void OnDragEnter(DragEventArgs drgevent)
		{
			base.OnDragEnter (drgevent);

			if (drgevent.Data.GetDataPresent(DataFormats.Text))  
				drgevent.Effect=DragDropEffects.Copy;  
			else  
				drgevent.Effect=DragDropEffects.None; 
 

		}
		
		
		void ParseLine(string line) 
		{
			//Ignore the case whitespace character
			Regex r=new Regex("([ \\t{}<>():;=&\"])");
			String [] tokens=r.Split(line); 
			// Check whether the token is a keyword. 

			foreach (string token in tokens) 
			{ 
				// Set the tokens default color and font.				
				this.SelectionColor=Color.Black;
				this.SelectionFont=new Font("Courier New", 10, 
					FontStyle.Regular); 

				bool found=false;
				for (int i=0; i < keywords.Length; i++) 
				{
					if (keywords[i] == token) 
					{
						// Apply alternative color and font to highlight keyword.
						this.SelectionColor=Color.Blue;
						this.SelectionFont=new Font("Courier New", 10,
							FontStyle.Bold);
						found=true;
						break;
					}
				}
				for (int i=0; !found && i < operators.Length; i++) 
				{
					if (operators[i] == token) 
					{
						// Apply alternative color and font to highlight keyword.
						this.SelectionColor=Color.Red ;
						this.SelectionFont=new Font("Courier New", 10,
							FontStyle.Bold);
								
						break;
					}
				}

				this.SelectedText=token;				
			} 
			this.SelectedText =this.SelectedText + Environment.NewLine ;
		} 



		public void HighLightSyntax(string input)
		{			
			if (input == null || input =="") return;
			Regex r=new Regex("\\n");
			String [] lines=r.Split(input);
			foreach (string l in lines) 
			{
				ParseLine(l);
			}
			
		}

		protected override void OnTextChanged(EventArgs e)
		{			
			base.OnTextChanged (e);			

			string str=this.Text;

			IsEmpty=(str == null || str == string.Empty);
			
			int i= this.SelectionStart ;
			this.Text="";
			HighLightSyntax (str);	
			this.SelectionStart=i;
		}



	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Thanh Dao
Software Developer
Vietnam Vietnam
I'm still alive...but temporarily moved to work on mobile & web stuffs(j2me/brew/php/flash...something not M$). things have just been very busy, and probably will continue...so don't have chance to maintain & respond. Hope will have time to try to write again, because many ideas with WPF &silver light are waiting. wish me luck Smile | :)

FYI:
- MESHSimPack project(c# library for measuring similarity among concepts of the MESH ontology):
http://sourceforge.net/projects/meshsimpack.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 25 Nov 2005
Article Copyright 2005 by Thanh Dao
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid