Update of /cvsroot/mvp-xml/Design/v1/src/CustomTools/XsdInfer
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28388/v1/src/CustomTools/XsdInfer
Added Files:
Infer.cs Readme.txt XsdInfer.cs
Log Message:
--- NEW FILE: Infer.cs ---
using System;
using System.IO;
using System.Xml;
using System.Xml.Schema;
using System.Collections;
using System.Diagnostics;
using System.Globalization;
namespace Microsoft.XsdInference
{
/// <summary>
/// Infer class serves for infering XML Schema from given XML instance document.
/// </summary>
/// <remarks>See http://apps.gotdotnet.com/xmltools/xsdinference/.</remarks>
internal class Infer
{
internal static XmlQualifiedName ST_boolean = new XmlQualifiedName("boolean", XmlSchema.Namespace);
internal static XmlQualifiedName ST_byte = new XmlQualifiedName("byte", XmlSchema.Namespace);
internal static XmlQualifiedName ST_unsignedByte = new XmlQualifiedName("unsignedByte", XmlSchema.Namespace);
[...1948 lines suppressed...]
newElement.IsAbstract = copyElement.IsAbstract;
if (copyElement.IsNillable)
{
newElement.IsNillable = copyElement.IsNillable;
}
newElement.LineNumber = copyElement.LineNumber;
newElement.LinePosition = copyElement.LinePosition;
newElement.Name = copyElement.Name;
newElement.Namespaces = copyElement.Namespaces;
newElement.RefName = copyElement.RefName;
newElement.SchemaType = copyElement.SchemaType;
newElement.SchemaTypeName = copyElement.SchemaTypeName;
newElement.SourceUri = copyElement.SourceUri;
newElement.SubstitutionGroup = copyElement.SubstitutionGroup;
newElement.UnhandledAttributes = copyElement.UnhandledAttributes;
return newElement;
}
}
}
--- NEW FILE: XsdInfer.cs ---
#region Usage
/* Usage:
* Add an .xml file to the project and set:
* Custom Tool: XsdInfer
*/
#endregion Usage
#region using
using System;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Xml;
using System.Xml.Schema;
using Microsoft.XsdInference;
#endregion
namespace Mvp.Xml.Design.CustomTools
{
/// <summary>
/// Processes XSD files and generates the corresponding classes.
/// </summary>
[Guid("37882B13-FBC3-46ef-90B2-249504DC6925")]
[CustomTool("XsdInference", "Microsoft IPE XSD Inference", false)]
[ComVisible(true)]
[VersionSupport("7.1")]
[VersionSupport("7.0")]
[CategorySupport(CategorySupportAttribute.CSharpCategory)]
[CategorySupport(CategorySupportAttribute.VBCategory)]
public class XsdInfer : CustomTool
{
#region GenerateCode
/// <summary>
/// Generates the output.
/// </summary>
protected override byte[] GenerateCode(string inputFileName, string inputFileContent)
{
try
{
Infer inf = new Infer();
using (Stream fs = File.OpenRead(inputFileName))
{
XmlSchemaCollection col = inf.InferSchema(new XmlTextReader(fs));
using (MemoryStream mem = new MemoryStream())
{
XmlTextWriter tw = new XmlTextWriter(mem, System.Text.Encoding.UTF8);
foreach (XmlSchema sch in col)
{
// Can there be multiple ones?!
sch.Write(tw);
}
return mem.ToArray();
}
}
}
catch(Exception e)
{
return System.Text.Encoding.ASCII.GetBytes(
String.Format("#error Couldn't generate code!\n/*\n{0}\n*/", e));
}
}
#endregion GenerateCode
#region GetDefaultExtension
/// <summary>
/// This tool generates XML Schema files.
/// </summary>
public override string GetDefaultExtension()
{
return ".xsd";
}
#endregion GetDefaultExtension
#region Registration and Installation
/// <summary>
/// Registers the generator.
/// </summary>
[ComRegisterFunction]
public static void RegisterClass(Type type)
{
CustomTool.Register(typeof(XsdInfer));
}
/// <summary>
/// Unregisters the generator.
/// </summary>
[ComUnregisterFunction]
public static void UnregisterClass(Type t)
{
CustomTool.UnRegister(typeof(XsdInfer));
}
#endregion Registration and Installation
}
}
--- NEW FILE: Readme.txt ---
Update from:
http://apps.gotdotnet.com/xmltools/xsdinference/
Released by Microsoft.
|