本文整理汇总了C#中System.Xml.Serialization.XmlSchemas.Add方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemas.Add方法的具体用法?C# XmlSchemas.Add怎么用?C# XmlSchemas.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Serialization.XmlSchemas
的用法示例。
在下文中一共展示了XmlSchemas.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateCode
public static CodeNamespace GenerateCode(Stream schemaStream, string classesNamespace)
{
// Open schema
XmlSchema schema = XmlSchema.Read(schemaStream, null);
XmlSchemas schemas = new XmlSchemas();
schemas.Add(schema);
schemas.Compile(null, true);
// Generate code
CodeNamespace code = new CodeNamespace(classesNamespace);
XmlSchemaImporter importer = new XmlSchemaImporter(schemas);
XmlCodeExporter exporter = new XmlCodeExporter(code);
foreach (XmlSchemaElement element in schema.Elements.Values) {
XmlTypeMapping mapping = importer.ImportTypeMapping(element.QualifiedName);
exporter.ExportTypeMapping(mapping);
}
// Modify generated code using extensions
schemaStream.Position = 0; // Rewind stream to the start
XPathDocument xPathDoc = new XPathDocument(schemaStream);
CodeGenerationContext context = new CodeGenerationContext(code, schema, xPathDoc);
new ExplicitXmlNamesExtension().ApplyTo(context);
new DocumentationExtension().ApplyTo(context);
new FixXmlTextAttributeExtension().ApplyTo(context);
new ArraysToGenericExtension().ApplyTo(context);
new CamelCaseExtension().ApplyTo(context);
new GetByIDExtension().ApplyTo(context);
return code;
}
示例2: Process
public static CodeNamespace Process(string xsdFile,
string targetNamespace)
{
// Load the XmlSchema and its collection.
XmlSchema xsd;
using (FileStream fs = new FileStream("Untitled1.xsd", FileMode.Open))
{
xsd = XmlSchema.Read(fs, null);
xsd.Compile(null);
}
XmlSchemas schemas = new XmlSchemas();
schemas.Add(xsd);
// Create the importer for these schemas.
XmlSchemaImporter importer = new XmlSchemaImporter(schemas);
// System.CodeDom namespace for the XmlCodeExporter to put classes in.
CodeNamespace ns = new CodeNamespace(targetNamespace);
XmlCodeExporter exporter = new XmlCodeExporter(ns);
// Iterate schema top-level elements and export code for each.
foreach (XmlSchemaElement element in xsd.Elements.Values)
{
// Import the mapping first.
XmlTypeMapping mapping = importer.ImportTypeMapping(
element.QualifiedName);
// Export the code finally.
exporter.ExportTypeMapping(mapping);
}
return ns;
}
示例3: Bug360541
public void Bug360541 ()
{
XmlSchemaComplexType stype = GetStype ();
XmlSchemaElement selem1 = new XmlSchemaElement ();
selem1.Name = "schema";
selem1.SchemaType = stype;
XmlSchema schema = new XmlSchema ();
schema.Items.Add (selem1);
XmlSchemas xs = new XmlSchemas ();
xs.Add (schema);
xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement));
selem1 = new XmlSchemaElement ();
selem1.Name = "schema1";
selem1.SchemaType = stype;
schema = new XmlSchema ();
schema.Items.Add (selem1);
xs = new XmlSchemas ();
xs.Add (schema);
xs.Find (XmlQualifiedName.Empty, typeof (XmlSchemaElement));
}
示例4: Main
private static void Main(string[] args)
{
XmlSchema rootSchema = GetSchemaFromFile("fpml-main-4-2.xsd");
var schemaSet = new List<XmlSchemaExternal>();
ExtractIncludes(rootSchema, ref schemaSet);
var schemas = new XmlSchemas { rootSchema };
schemaSet.ForEach(schemaExternal => schemas.Add(GetSchemaFromFile(schemaExternal.SchemaLocation)));
schemas.Compile(null, true);
var xmlSchemaImporter = new XmlSchemaImporter(schemas);
var codeNamespace = new CodeNamespace("Hosca.FpML4_2");
var xmlCodeExporter = new XmlCodeExporter(codeNamespace);
var xmlTypeMappings = new List<XmlTypeMapping>();
foreach (XmlSchemaType schemaType in rootSchema.SchemaTypes.Values)
xmlTypeMappings.Add(xmlSchemaImporter.ImportSchemaType(schemaType.QualifiedName));
foreach (XmlSchemaElement schemaElement in rootSchema.Elements.Values)
xmlTypeMappings.Add(xmlSchemaImporter.ImportTypeMapping(schemaElement.QualifiedName));
xmlTypeMappings.ForEach(xmlCodeExporter.ExportTypeMapping);
CodeGenerator.ValidateIdentifiers(codeNamespace);
foreach (CodeTypeDeclaration codeTypeDeclaration in codeNamespace.Types)
{
for (int i = codeTypeDeclaration.CustomAttributes.Count - 1; i >= 0; i--)
{
CodeAttributeDeclaration cad = codeTypeDeclaration.CustomAttributes[i];
if (cad.Name == "System.CodeDom.Compiler.GeneratedCodeAttribute")
codeTypeDeclaration.CustomAttributes.RemoveAt(i);
}
}
using (var writer = new StringWriter())
{
new CSharpCodeProvider().GenerateCodeFromNamespace(codeNamespace, writer, new CodeGeneratorOptions());
//Console.WriteLine(writer.GetStringBuilder().ToString());
File.WriteAllText(Path.Combine(rootFolder, "FpML4_2.Generated.cs"), writer.GetStringBuilder().ToString());
}
Console.ReadLine();
}
示例5: AddDocument
internal static void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions, StringCollection warnings)
{
ServiceDescription serviceDescription = document as ServiceDescription;
if (serviceDescription != null)
{
descriptions.Add(serviceDescription);
}
else
{
XmlSchema schema = document as XmlSchema;
if (schema != null)
{
schemas.Add(schema);
}
}
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:16,代码来源:ServiceDescriptionImporter.cs
示例6: ExportEndpoint
internal static void ExportEndpoint(WsdlExporter wsdlExporter)
{
if (wsdlExporter.GeneratedWsdlDocuments.Count > 1)
throw new ApplicationException("Single file option is not supported in multiple wsdl files");
ServiceDescription rootDescription = wsdlExporter.GeneratedWsdlDocuments[0];
XmlSchemas imports = new XmlSchemas();
foreach (XmlSchema schema in wsdlExporter.GeneratedXmlSchemas.Schemas())
{
imports.Add(schema);
}
foreach (XmlSchema schema in imports)
{
schema.Includes.Clear();
}
rootDescription.Types.Schemas.Clear();
rootDescription.Types.Schemas.Add(imports);
}
示例7: ExportEndpoint
public void ExportEndpoint()
{
ModuleProc PROC = new ModuleProc(this.DYN_MODULE_NAME, "ExportEndpoint");
try
{
System.Web.Services.Description.ServiceDescription wsdl = _exporter.GeneratedWsdlDocuments[0];
XmlSchemaSet schemaSet = _exporter.GeneratedXmlSchemas;
XmlSchemas imports = new XmlSchemas();
foreach (XmlSchema schema in _exporter.GeneratedXmlSchemas.Schemas())
{
imports.Add(schema);
}
foreach (XmlSchema schema in imports)
{
schema.Includes.Clear();
}
wsdl.Types.Schemas.Clear();
wsdl.Types.Schemas.Add(imports);
//List<XmlSchema> importsList = new List<XmlSchema>();
// foreach (XmlSchema schema in wsdl.Types.Schemas)
// {
// AddImportedSchemas(schema, schemaSet, importsList);
// }
// wsdl.Types.Schemas.Clear();
// foreach (XmlSchema schema in importsList)
// {
// RemoveXsdImports(schema);
// wsdl.Types.Schemas.Add(schema);
// }
//}
}
catch (Exception ex)
{
Log.Exception(PROC, ex);
}
}
示例8: Generate
public static void Generate (ArrayList services, ArrayList schemas, string binOper, string protocol)
{
ServiceDescriptionCollection descCol = new ServiceDescriptionCollection ();
foreach (ServiceDescription sd in services)
descCol.Add (sd);
XmlSchemas schemaCol;
if (schemas.Count > 0) {
schemaCol = new XmlSchemas ();
foreach (XmlSchema sc in schemas)
schemaCol.Add (sc);
}
else
schemaCol = descCol[0].Types.Schemas;
string oper, bin = null;
int i = binOper.IndexOf ('/');
if (i != -1) {
oper = binOper.Substring (i+1);
bin = binOper.Substring (0,i);
}
else
oper = binOper;
ConsoleSampleGenerator sg = new ConsoleSampleGenerator (descCol, schemaCol);
string req, resp;
sg.GenerateMessages (oper, bin, protocol, out req, out resp);
Console.WriteLine ();
Console.WriteLine ("Sample request message:");
Console.WriteLine ();
Console.WriteLine (req);
Console.WriteLine ();
Console.WriteLine ("Sample response message:");
Console.WriteLine ();
Console.WriteLine (resp);
}
示例9: AddDocument
private void AddDocument(string path, object document, XmlSchemas schemas, ServiceDescriptionCollection descriptions)
{
ServiceDescription serviceDescription = document as ServiceDescription;
if (serviceDescription != null)
{
if (descriptions[serviceDescription.TargetNamespace] == null)
{
descriptions.Add(serviceDescription);
StringWriter w = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(w);
writer.Formatting = Formatting.Indented;
serviceDescription.Write(writer);
this.wsdls.Add(w.ToString());
}
else
{
this.CheckPoint(MessageType.Warning, string.Format(duplicateService, serviceDescription.TargetNamespace, path));
}
}
else
{
XmlSchema schema = document as XmlSchema;
if (schema != null)
{
if (schemas[schema.TargetNamespace] == null)
{
schemas.Add(schema);
StringWriter writer3 = new StringWriter();
XmlTextWriter writer4 = new XmlTextWriter(writer3);
writer4.Formatting = Formatting.Indented;
schema.Write(writer4);
this.xsds.Add(writer3.ToString());
}
else
{
this.CheckPoint(MessageType.Warning, string.Format(duplicateSchema, serviceDescription.TargetNamespace, path));
}
}
}
}
示例10: GenerateClasses
private static void GenerateClasses(CodeNamespace code, XmlSchema schema)
{
XmlSchemas schemas = new XmlSchemas();
schemas.Add(schema);
XmlSchemaImporter importer = new XmlSchemaImporter(schemas);
CodeCompileUnit codeCompileUnit = new CodeCompileUnit();
CodeGenerationOptions options = CodeGenerationOptions.None;
XmlCodeExporter exporter = new XmlCodeExporter(code, codeCompileUnit, options);
foreach (XmlSchemaObject item in schema.Items)
{
XmlSchemaElement element = item as XmlSchemaElement;
if (element != null)
{
XmlQualifiedName name = new XmlQualifiedName(element.Name, schema.TargetNamespace);
XmlTypeMapping map = importer.ImportTypeMapping(name);
exporter.ExportTypeMapping(map);
}
}
}
示例11: GeneratedClassFromStream
private CodeNamespace GeneratedClassFromStream(Stream stream, string nameSpace)
{
XmlSchema xsd;
stream.Seek(0, SeekOrigin.Begin);
using (stream)
{
xsd = XmlSchema.Read(stream, null);
}
XmlSchemas xsds = new XmlSchemas();
xsds.Add(xsd);
xsds.Compile(null, true);
XmlSchemaImporter schemaImporter = new XmlSchemaImporter(xsds);
// create the codedom
CodeNamespace codeNamespace = new CodeNamespace(nameSpace);
XmlCodeExporter codeExporter = new XmlCodeExporter(codeNamespace);
List<XmlTypeMapping> maps = new List<XmlTypeMapping>();
foreach (XmlSchemaType schemaType in xsd.SchemaTypes.Values)
{
maps.Add(schemaImporter.ImportSchemaType(schemaType.QualifiedName));
}
foreach (XmlSchemaElement schemaElement in xsd.Elements.Values)
{
maps.Add(schemaImporter.ImportTypeMapping(schemaElement.QualifiedName));
}
foreach (XmlTypeMapping map in maps)
{
codeExporter.ExportTypeMapping(map);
}
this.RemoveUnusedStuff(codeNamespace);
return codeNamespace;
}
示例12: Run
public void Run(string src, string dest)
{
// Load the schema to process.
XmlSchema xsd;
using (Stream stm = File.OpenRead(src))
xsd = XmlSchema.Read(stm, null);
// Collection of schemas for the XmlSchemaImporter
XmlSchemas xsds = new XmlSchemas();
xsds.Add(xsd);
XmlSchemaImporter imp = new XmlSchemaImporter(xsds);
// System.CodeDom namespace for the XmlCodeExporter to put classes in
CodeNamespace ns = new CodeNamespace("NHibernate.Mapping.Hbm");
CodeCompileUnit ccu = new CodeCompileUnit();
XmlCodeExporter exp = new XmlCodeExporter(ns, ccu, ~CodeGenerationOptions.GenerateProperties);
// Iterate schema items (top-level elements only) and generate code for each
foreach (XmlSchemaObject item in xsd.Items)
{
if (item is XmlSchemaElement)
{
// Import the mapping first
XmlTypeMapping map = imp.ImportTypeMapping(new XmlQualifiedName(((XmlSchemaElement)item).Name, xsd.TargetNamespace));
// Export the code finally
exp.ExportTypeMapping(map);
}
}
ns.Imports.Add(new CodeNamespaceImport("Ayende.NHibernateQueryAnalyzer.SchemaEditing"));
AddRequiredTags(ns, xsd);
// Code generator to build code with.
CodeDomProvider generator = new CSharpCodeProvider();
// Generate untouched version
using (StreamWriter sw = new StreamWriter(dest, false))
generator.GenerateCodeFromNamespace(ns, sw, new CodeGeneratorOptions());
}
示例13: Process
public static CodeNamespace Process(string xsdSchema, string targetNamespace)
{
// Load the XmlSchema and its collection.
XmlSchema xsd;
using (var fs = new StringReader(xsdSchema))
{
xsd = XmlSchema.Read(fs, null);
xsd.Compile(null);
}
XmlSchemas schemas = new XmlSchemas();
schemas.Add(xsd);
// Create the importer for these schemas.
XmlSchemaImporter importer = new XmlSchemaImporter(schemas);
// System.CodeDom namespace for the XmlCodeExporter to put classes in.
CodeNamespace ns = new CodeNamespace(targetNamespace);
XmlCodeExporter exporter = new XmlCodeExporter(ns);
// Iterate schema top-level elements and export code for each.
foreach (XmlSchemaElement element in xsd.Elements.Values)
{
// Import the mapping first.
XmlTypeMapping mapping = importer.ImportTypeMapping(
element.QualifiedName);
// Export the code finally.
exporter.ExportTypeMapping(mapping);
}
// execute extensions
//var collectionsExt = new ArraysToCollectionsExtension();
//collectionsExt.Process(ns, xsd);
//var filedsExt = new FieldsToPropertiesExtension();
//filedsExt.Process(ns, xsd);
return ns;
}
示例14: GenerateClasses
public ObjectCollection GenerateClasses(XmlSchema schema)
{
#region Generate the CodeDom from the XSD
CodeNamespace codeNamespace = new CodeNamespace("TestNameSpace");
XmlSchemas xmlSchemas = new XmlSchemas();
xmlSchemas.Add(schema);
XmlSchemaImporter schemaImporter = new XmlSchemaImporter(xmlSchemas);
XmlCodeExporter codeExporter = new XmlCodeExporter(
codeNamespace,
new CodeCompileUnit(),
CodeGenerationOptions.GenerateProperties);
foreach (XmlSchemaElement element in schema.Elements.Values)
{
try
{
XmlTypeMapping map = schemaImporter.ImportTypeMapping(element.QualifiedName);
codeExporter.ExportTypeMapping(map);
}
catch (Exception ex)
{
throw new Exception("Error Loading Schema: ", ex);
}
}
#endregion
#region Modify the CodeDom
foreach (ICodeModifier codeModifier in m_codeModifiers)
codeModifier.Execute(codeNamespace);
#endregion
#region Generate the code
CodeCompileUnit compileUnit = new CodeCompileUnit();
compileUnit.Namespaces.Add(codeNamespace);
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
#if DEBUG
StringWriter sw = new StringWriter();
CodeGeneratorOptions options = new CodeGeneratorOptions();
options.VerbatimOrder = true;
provider.GenerateCodeFromCompileUnit(compileUnit, sw, options);
m_codeString = sw.ToString();
#endif
#endregion
#region Compile an assembly
CompilerParameters compilerParameters = new CompilerParameters();
#region add references to assemblies
// reference for
// System.CodeDom.Compiler
// System.CodeDom
// System.Diagnostics
compilerParameters.ReferencedAssemblies.Add("System.dll");
compilerParameters.ReferencedAssemblies.Add("mscorlib.dll");
// System.Xml
compilerParameters.ReferencedAssemblies.Add("system.xml.dll");
// reference to this assembly for the custom collection editor
compilerParameters.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
compilerParameters.ReferencedAssemblies.Add("System.Drawing.dll");
// System.ComponentModel
#endregion
compilerParameters.GenerateExecutable = false;
compilerParameters.GenerateInMemory = true;
CompilerResults results = provider.CompileAssemblyFromDom(compilerParameters, new CodeCompileUnit[] { compileUnit });
// handle the errors if there are any
if (results.Errors.HasErrors)
{
m_errorStrings = new StringCollection();
m_errorStrings.Add("Error compiling assembly:\r\n");
foreach (CompilerError error in results.Errors)
m_errorStrings.Add(error.ErrorText + "\r\n");
return null;
}
#endregion
#region Find the exported classes
Assembly assembly = results.CompiledAssembly;
Type[] exportedTypes = assembly.GetExportedTypes();
// try to create an instance of the exported types
ObjectCollection objectCollection = new ObjectCollection();
objectCollection.Clear();
foreach (Type type in exportedTypes)
{
object obj = Activator.CreateInstance(type);
objectCollection.Add(new ObjectItem(type.Name, obj));
}
//.........这里部分代码省略.........
示例15: GetSchemas
//Helper methods
XmlSchemas GetSchemas (XmlSchemaSet set)
{
XmlSchemas schemas = new XmlSchemas ();
foreach (XmlSchema schema in set.Schemas ())
schemas.Add (schema);
return schemas;
}