Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

UDDI Explorer: Tool for Searching Web Services

Rate me:
Please Sign up or sign in to vote.
4.93/5 (49 votes)
20 Dec 200517 min read 221.8K   3.2K   109  
Tool for searching web service(s) and viewing their WSDL information
//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.Formatting=Formatting.Indented;
			writer.WriteStartDocument ();					
			prefIndex=-1;
			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 )
				{
					++prefIndex;
					string pref=writer.LookupPrefix (data.Namespace);
					
					if (pref == null) pref="m"+prefIndex;

					writer.WriteStartElement(pref, name, data.Namespace) ;					
				}
				else
					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))
					{
						ct=true;
						WriteNode(writer, child);
					}
				};
				
				if (!ct)writer.WriteString (data.Type);

				writer.WriteEndElement();
				
			} 
		}
	}
}

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.


Written By
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.

Comments and Discussions