本文整理汇总了C#中System.Xml.Serialization.XmlSchemas类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemas类的具体用法?C# XmlSchemas怎么用?C# XmlSchemas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemas类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlSchemas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddItem
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas)
{
if (item == null)
{
return null;
}
if ((qname == null) || qname.IsEmpty)
{
return null;
}
string str = item.GetType().Name + ":" + qname.ToString();
ArrayList list = (ArrayList) this.ObjectCache[str];
if (list == null)
{
list = new ArrayList();
this.ObjectCache[str] = list;
}
for (int i = 0; i < list.Count; i++)
{
XmlSchemaObject obj2 = (XmlSchemaObject) list[i];
if (obj2 == item)
{
return obj2;
}
if (this.Match(obj2, item, true))
{
return obj2;
}
this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace }));
this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string) this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string) this.looks[item]));
}
list.Add(item);
return item;
}
示例2: ImportSchemaType
//public override string ImportSchemaType(
// string name,
// string ns,
// XmlSchemaObject context,
// XmlSchemas schemas,
// XmlSchemaImporter importer,
// CodeCompileUnit compileUnit,
// CodeNamespace mainNamespace,
// CodeGenerationOptions options,
// CodeDomProvider codeProvider)
//{
// XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType) schemas.Find(new XmlQualifiedName(name, ns), typeof(XmlSchemaSimpleType));
// return ImportSchemaType(
// simpleType,
// context,
// schemas,
// importer,
// compileUnit,
// mainNamespace,
// options,
// codeProvider);
//}
public override string ImportSchemaType(
XmlSchemaType type,
XmlSchemaObject context,
XmlSchemas schemas,
XmlSchemaImporter importer,
CodeCompileUnit compileUnit,
CodeNamespace mainNamespace,
CodeGenerationOptions options,
CodeDomProvider codeProvider)
{
XmlSchemaAnnotated annotatedType = type as XmlSchemaAnnotated;
if (annotatedType == null)
return null;
if (annotatedType.Annotation == null)
return null;
// create the comments and add them to the hash table under the namespace of the object
CreateComments(annotatedType);
//mainNamespace.Types.
return null;
}
示例3: GenerateTypedDataSet
internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeNamespace codeNamespace, StringCollection references, CodeDomProvider codeProvider)
{
if (element == null)
{
return null;
}
if (this.importedTypes[element.SchemaType] != null)
{
return (string) this.importedTypes[element.SchemaType];
}
IList list = schemas.GetSchemas(element.QualifiedName.Namespace);
if (list.Count != 1)
{
return null;
}
XmlSchema schema = list[0] as XmlSchema;
if (schema == null)
{
return null;
}
DataSet dataSet = new DataSet();
using (MemoryStream stream = new MemoryStream())
{
schema.Write(stream);
stream.Position = 0L;
dataSet.ReadXmlSchema(stream);
}
string name = new TypedDataSetGenerator().GenerateCode(dataSet, codeNamespace, codeProvider.CreateGenerator()).Name;
this.importedTypes.Add(element.SchemaType, name);
references.Add("System.Data.dll");
return name;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:DataSetSchemaImporterExtension.cs
示例4: ImportSchemaType
public override string ImportSchemaType(
string name,
string ns,
XmlSchemaObject context,
XmlSchemas schemas,
XmlSchemaImporter importer,
CodeCompileUnit compileUnit,
CodeNamespace codeNamespace,
CodeGenerationOptions options,
CodeDomProvider codeGenerator)
{
if (IsBaseType(name, ns))
{
return base.ImportSchemaType(name, ns,
context, schemas,
importer,
compileUnit, codeNamespace,
options, codeGenerator);
}
// Add the Namespace, except the first
for (int i = 1; i < ImportNamespaces.Length; i++)
{
string _Import = ImportNamespaces[i];
codeNamespace.Imports.Add(new CodeNamespaceImport(_Import));
}
return name;
}
示例5: XmlSchemaImporter
public XmlSchemaImporter (XmlSchemas schemas)
{
this.schemas = schemas;
typeIdentifiers = new CodeIdentifiers ();
InitializeExtensions ();
}
示例6: 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));
}
示例7: AddSchemaImports
private void AddSchemaImports(XmlSchemas schemas, string uri, ServiceDescriptionCollection descriptions)
{
int num = 0;
foreach (XmlSchema schema in schemas)
{
if (schema != null)
{
if ((schema.Id == null) || (schema.Id.Length == 0))
{
schema.Id = "schema" + ++num.ToString(CultureInfo.InvariantCulture);
}
string location = uri + "?schema=" + schema.Id;
foreach (ServiceDescription description in descriptions)
{
if (description.Types.Schemas.Count == 0)
{
XmlSchema schema2 = new XmlSchema {
TargetNamespace = description.TargetNamespace
};
schema.ElementFormDefault = XmlSchemaForm.Qualified;
this.AddExternal(schema2, schema.TargetNamespace, location);
description.Types.Schemas.Add(schema2);
}
else
{
this.AddExternal(description.Types.Schemas[0], schema.TargetNamespace, location);
}
}
this.schemaTable.Add(schema.Id, schema);
}
}
}
示例8: ImportSchemaType
public override string ImportSchemaType(XmlSchemaType type, XmlSchemaObject context, XmlSchemas schemas, XmlSchemaImporter importer, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeGenerationOptions options, CodeDomProvider codeProvider) {
if (type == null) {
return null;
}
if (importedTypes[type] != null) {
mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataSet).Namespace));
compileUnit.ReferencedAssemblies.Add("System.Data.dll");
return (string)importedTypes[type];
}
if (!(context is XmlSchemaElement))
return null;
if (type is XmlSchemaComplexType) {
XmlSchemaComplexType ct = (XmlSchemaComplexType)type;
if (ct.Particle is XmlSchemaSequence) {
XmlSchemaObjectCollection items = ((XmlSchemaSequence)ct.Particle).Items;
if (items.Count == 2 && items[0] is XmlSchemaAny && items[1] is XmlSchemaAny) {
XmlSchemaAny any0 = (XmlSchemaAny)items[0];
XmlSchemaAny any1 = (XmlSchemaAny)items[1];
if (any0.Namespace == XmlSchema.Namespace && any1.Namespace == "urn:schemas-microsoft-com:xml-diffgram-v1") {
string typeName = typeof(DataTable).FullName;
importedTypes.Add(type, typeName);
mainNamespace.Imports.Add(new CodeNamespaceImport(typeof(DataTable).Namespace));
compileUnit.ReferencedAssemblies.Add("System.Data.dll");
return typeName;
}
}
}
}
return null;
}
示例9: SchemaImporter
internal SchemaImporter(XmlSchemas schemas, CodeGenerationOptions options, CodeDomProvider codeProvider, System.Xml.Serialization.ImportContext context)
{
if (!schemas.Contains("http://www.w3.org/2001/XMLSchema"))
{
schemas.AddReference(XmlSchemas.XsdSchema);
schemas.SchemaSet.Add(XmlSchemas.XsdSchema);
}
if (!schemas.Contains("http://www.w3.org/XML/1998/namespace"))
{
schemas.AddReference(XmlSchemas.XmlSchema);
schemas.SchemaSet.Add(XmlSchemas.XmlSchema);
}
this.schemas = schemas;
this.options = options;
this.codeProvider = codeProvider;
this.context = context;
this.Schemas.SetCache(this.Context.Cache, this.Context.ShareTypes);
SchemaImporterExtensionsSection section = System.Configuration.PrivilegedConfigurationManager.GetSection(ConfigurationStrings.SchemaImporterExtensionsSectionPath) as SchemaImporterExtensionsSection;
if (section != null)
{
this.extensions = section.SchemaImporterExtensionsInternal;
}
else
{
this.extensions = new SchemaImporterExtensionCollection();
}
}
示例10: GenerateTypedDataSet
internal string GenerateTypedDataSet(XmlSchemaElement element, XmlSchemas schemas, CodeCompileUnit compileUnit, CodeNamespace mainNamespace, CodeDomProvider codeProvider)
{
if (element == null)
{
return null;
}
if (this.importedTypes[element.SchemaType] != null)
{
return (string) this.importedTypes[element.SchemaType];
}
IList list = schemas.GetSchemas(element.QualifiedName.Namespace);
if (list.Count != 1)
{
return null;
}
XmlSchema schema = list[0] as XmlSchema;
if (schema == null)
{
return null;
}
MemoryStream stream = new MemoryStream();
schema.Write(stream);
stream.Position = 0L;
DesignDataSource designDS = new DesignDataSource();
designDS.ReadXmlSchema(stream, null);
stream.Close();
string str = TypedDataSetGenerator.GenerateInternal(designDS, compileUnit, mainNamespace, codeProvider, this.dataSetGenerateOptions, null);
this.importedTypes.Add(element.SchemaType, str);
return str;
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:30,代码来源:TypedDataSetSchemaImporterExtension.cs
示例11: 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;
}
示例12: ImportSchemaType
public override string ImportSchemaType(
string name,
string ns,
XmlSchemaObject context,
XmlSchemas schemas,
XmlSchemaImporter importer,
CodeCompileUnit compileUnit,
CodeNamespace mainNamespace,
CodeGenerationOptions options,
CodeDomProvider codeProvider)
{
if (ns != "http://www.w3.org/2001/XMLSchema")
return null;
switch (name)
{
case "anyURI": return "System.Uri";
case "gDay": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDay";
case "gMonth": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonth";
case "gMonthDay": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapMonthDay";
case "gYear": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYear";
case "gYearMonth": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapYearMonth";
case "duration": return "System.Runtime.Remoting.Metadata.W3cXsd2001.SoapDuration";
default: return null;
}
}
示例13: 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;
}
示例14: Compile
internal static StringCollection Compile(XmlSchemas schemas)
{
AddImports(schemas);
Warnings.Clear();
schemas.Compile(new ValidationEventHandler(SchemaCompiler.ValidationCallbackWithErrorCode), true);
return Warnings;
}
示例15: ServiceDescriptionImporter
public ServiceDescriptionImporter ()
{
protocolName = String.Empty;
schemas = new XmlSchemas ();
serviceDescriptions = new ServiceDescriptionCollection ();
serviceDescriptions.SetImporter (this);
style = ServiceDescriptionImportStyle.Client;
}