Click here to Skip to main content
12,951,034 members (59,369 online)
Click here to Skip to main content


61 bookmarked
Posted 21 Nov 2005

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.netusing System;
using System.IO;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Schema;

namespace WSDLParser
	/// <summary>
	/// Summary description for XMLGenerator.
	/// </summary>
	public class XMLGenerator
		public XMLGenerator()

		public static string GetXmlSample(TreeNode node)
			StringWriter sw=new StringWriter ();
			XmlTextWriter writer=new XmlTextWriter (sw);
			writer.WriteStartDocument ();					
			WriteNode(writer, node);
			writer.Close() ;
			return sw.ToString() ;

		static int prefIndex=0;

		private static  void WriteNode(XmlTextWriter writer, TreeNode node)
			SchemaParser.NodeData data=null;
			if (node.Tag != null)
				data=node.Tag as SchemaParser.NodeData ;
			if (data == null) return;			
			if (data.baseObj is XmlSchemaElement
				|| data.baseObj is XmlSchemaComplexType
				|| data.baseObj is XmlSchemaSimpleType

				//if (pref != null)  pref + ":" + node.Text;
				string name=node.Text;
				if (name.LastIndexOf(":") != -1)
					name=name.Substring(name.LastIndexOf(":") + 1, name.Length - name.LastIndexOf(":") - 1) ;

				if (data.Namespace != string.Empty )
					string pref=writer.LookupPrefix (data.Namespace);
					if (pref == null) pref="m"+prefIndex;

					writer.WriteStartElement(pref, name, data.Namespace) ;					
					writer.WriteStartElement(name) ;
				bool ct=false;
				if (node.Nodes.Count > 0)
					foreach (TreeNode child in node.Nodes)
						if (child.Tag is SchemaParser.NodeData)
							if (((SchemaParser.NodeData)child.Tag).baseObj is XmlSchemaAttribute)
								writer.WriteAttributeString(child.Text, ((SchemaParser.NodeData)child.Tag).Type );

					foreach (TreeNode child in node.Nodes)
					if (child.Tag is SchemaParser.NodeData)
					if (!(((SchemaParser.NodeData)child.Tag).baseObj is XmlSchemaAttribute))
						WriteNode(writer, child);
				if (!ct)writer.WriteString (data.Type);


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.


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


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 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 | :)

- MESHSimPack project(c# library for measuring similarity among concepts of the MESH ontology):

You may also be interested in...

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