本文整理汇总了C#中System.Xml.Schema.XmlSchemaSet.Compile方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaSet.Compile方法的具体用法?C# XmlSchemaSet.Compile怎么用?C# XmlSchemaSet.Compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Schema.XmlSchemaSet
的用法示例。
在下文中一共展示了XmlSchemaSet.Compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ArgumentNullException
void IWsdlImportExtension.ImportContract (WsdlImporter importer,
WsdlContractConversionContext context)
{
if (!enabled)
return;
if (importer == null)
throw new ArgumentNullException ("importer");
if (context == null)
throw new ArgumentNullException ("context");
if (this.importer != null || this.context != null)
throw new SystemException ("INTERNAL ERROR: unexpected recursion of ImportContract method call");
dc_importer = new XsdDataContractImporter ();
schema_set_in_use = new XmlSchemaSet ();
schema_set_in_use.Add (importer.XmlSchemas);
foreach (WSDL wsdl in importer.WsdlDocuments)
foreach (XmlSchema xs in wsdl.Types.Schemas)
schema_set_in_use.Add (xs);
// commenting out this import operation, but might be required (I guess not).
//dc_importer.Import (schema_set_in_use);
schema_set_in_use.Compile ();
this.importer = importer;
this.context = context;
try {
DoImportContract ();
} finally {
this.importer = null;
this.context = null;
}
}
示例2: Read
public static SDataSchema Read(TextReader reader, string targetElementName)
{
var xsd = XmlSchema.Read(reader, null);
var schemaSet = new XmlSchemaSet();
schemaSet.Add(xsd);
schemaSet.Compile();
var resources = new Dictionary<string, SDataResource>();
foreach (DictionaryEntry entry in xsd.Elements)
{
var name = (XmlQualifiedName) entry.Key;
if (name.Namespace != xsd.TargetNamespace)
{
continue;
}
var resource = new SDataResource();
resource.Load(name, schemaSet);
resources.Add(name.Name, resource);
}
return new SDataSchema
{
TargetElementName = targetElementName,
Namespace = xsd.TargetNamespace,
Resources = resources
};
}
示例3: Verify
public void Verify(string resourceName)
{
// build a standard configurationsection with properties (using the mock object)
var enterpriseConfig = new EnterpriseConfig();
XmlHelper.UseAll = true;
var configType = enterpriseConfig.GetType();
var generator = new XsdGenerator(configType);
XmlSchema schema = generator.GenerateXsd(configType.FullName);
var schemaXml = SchemaToString(schema);
var schemas = new XmlSchemaSet();
schemas.Add("http://JFDI.Utils.XSDExtractor.UnitTests.ConfigurationClasses.EnterpriseConfig", XmlReader.Create(new StringReader(schemaXml)));
schemas.CompilationSettings.EnableUpaCheck = true;
schemas.Compile();
var assembly = Assembly.GetExecutingAssembly();
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
{
var doc = new XmlDocument();
doc.Load(stream);
doc.Schemas.Add(schemas);
Debug.WriteLine(doc.OuterXml);
Debug.WriteLine("------------------");
doc.Validate(((sender, args) =>
{
Debug.WriteLine("{0} {1}", args.Message, args.Severity);
Assert.Fail(args.Message);
}));
}
}
示例4: v3
public void v3(object param0, object param1, object param2, object param3, object param4)
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.XmlResolver = new XmlUrlResolver();
sc.Add((string)param3, TestData._Root + param1.ToString());
CError.Compare(sc.Count, 1, "AddCount");
CError.Compare(sc.IsCompiled, false, "AddIsCompiled");
sc.Compile();
CError.Compare(sc.Count, 1, "CompileCount");
CError.Compare(sc.IsCompiled, true, "CompileIsCompiled");
XmlSchema parent = sc.Add(null, TestData._Root + param0.ToString());
CError.Compare(sc.Count, param2, "Add2Count");
CError.Compare(sc.IsCompiled, false, "Add2IsCompiled");
// check that schema is present in parent.Includes and its NS correct.
foreach (XmlSchemaImport imp in parent.Includes)
if (imp.SchemaLocation.Equals(param1.ToString()) && imp.Schema.TargetNamespace == (string)param4)
return;
Assert.True(false);
}
示例5: v2
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.XmlResolver = new XmlUrlResolver();
XmlSchema schema = new XmlSchema();
sc.Add(null, TestData._XsdNoNs);
CError.Compare(sc.Count, 1, "AddCount");
CError.Compare(sc.IsCompiled, false, "AddIsCompiled");
sc.Compile();
CError.Compare(sc.IsCompiled, true, "IsCompiled");
CError.Compare(sc.Count, 1, "Count");
try
{
schema = sc.Add(null, Path.Combine(TestData._Root, "include_v2.xsd"));
}
catch (XmlSchemaException)
{
// no schema should be addded to the set.
CError.Compare(sc.Count, 1, "Count");
CError.Compare(sc.IsCompiled, true, "IsCompiled");
return;
}
Assert.True(false);
}
示例6: ProcessSchema
public bool ProcessSchema(string filePath)
{
if(String.IsNullOrWhiteSpace(filePath))
{
return false;
}
var schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
schemaSet.Add("urn:newrelic-config", filePath);
schemaSet.Compile();
XmlSchema schema = null;
foreach (XmlSchema TempSchema in schemaSet.Schemas())
{
schema = TempSchema;
}
var configurationElement = schema.Items[0] as XmlSchemaElement;
if (configurationElement != null)
{
ProcessElement(configurationElement, null);
ConfigurationFile.Xsd.RootElement = true;
}
return true;
}
示例7: SchemaSet
private SchemaSet() {
var schemaDir = Path.Combine(ApplicationInformation.Directory, RelativeSchemaDir);
if (!SchemaHasBeenCopied(schemaDir)) {
try {
if (Directory.Exists(schemaDir)) {
Directory.Delete(schemaDir, true);
}
Directory.CreateDirectory(schemaDir);
var assembly = GetType().Assembly;
var schemaResourcePrefix = string.Format("{0}.Resources.Schema.", assembly.GetName().Name);
var resources = assembly.GetManifestResourceNames();
foreach (var resource in resources.Where(r => r.StartsWith(schemaResourcePrefix))) {
var filename = Path.Combine(schemaDir, resource.Replace(schemaResourcePrefix, string.Empty));
using (var stream = new FileStream(filename, FileMode.CreateNew)) {
using (var manifestStream = assembly.GetManifestResourceStream(resource)) {
manifestStream.CopyTo(stream);
}
}
}
}
catch (Exception err) {
logger.ErrorFormat(Messages.Loader_Loader_FailedToLoadAndCompileSchema, err);
throw;
}
}
Schemas = new XmlSchemaSet();
Schemas.Add(Globals.JdfNamespace.NamespaceName, Path.Combine(schemaDir, "jdf.xsd"));
Schemas.Compile();
}
示例8: Validate
public IEnumerable<string> Validate(string fpml)
{
_failureMessages = new List<string>();
var xdoc = XDocument.Parse(fpml);
//TODO - this would be a lookup to allow multiple schema versions:
var version = "5-7";
var schemaLocation = @".\schema\fpml\reporting-merged-schema-5-7\fpml-main-5-7.xsd";
var reader = xdoc.CreateReader();
reader.Read();
if (!_SchemaSets.ContainsKey(version))
{
lock (_SchemaSetLock)
{
var schemaSet = new XmlSchemaSet(reader.NameTable);
schemaSet.Add(@"http://www.fpml.org/FpML-5/reporting", schemaLocation);
schemaSet.Compile();
_SchemaSets[version] = schemaSet;
}
}
xdoc.Validate(_SchemaSets[version], (sender, args) => _failureMessages.Add(args.Message));
return _failureMessages;
}
示例9: SchemaValidator
public SchemaValidator(string schemaNamespace, string schemaPath)
{
if (schemaNamespace == null)
{
throw new ArgumentNullException("schemaNamespace");
}
if (schemaNamespace.Length == 0)
{
throw new ArgumentException("schema namespace cannot be zero length!");
}
if (schemaPath == null)
{
throw new ArgumentNullException("schemaPath");
}
if (schemaPath.Length == 0)
{
throw new ArgumentException("schemaPath cannot be of zero length!");
}
if (!File.Exists(schemaPath))
{
throw new ArgumentException("Schema: " + schemaPath + " cannot be located!");
}
schemaSet = new XmlSchemaSet();
schemaSet.Add(schemaNamespace, schemaPath);
schemaSet.Compile();
}
示例10: LoadSchemaSetFromFileLocation
/// <summary>
/// Load an Schema From A File Location
/// </summary>
/// <param name="SchemaFileLocation">Schema File Location</param>
/// <param name="TargetNamespace">Default Namespace - Could be a blank string</param>
/// <returns>XmlSchemaSet Object</returns>
public static XmlSchemaSet LoadSchemaSetFromFileLocation(string SchemaFileLocation, string TargetNamespace)
{
//Make sure the file is there
if (!File.Exists(SchemaFileLocation))
{
throw new FileNotFoundException("Can't Find Schema File In: " + SchemaFileLocation);
}
//Make sure its a .xsd file
if (!string.Equals(new FileInfo(SchemaFileLocation).Extension, ".xsd", StringComparison.OrdinalIgnoreCase))
{
throw new InvalidDataException("Schema File Must Be Of Extension .xsd");
}
//*************Done with validation*************
//Schema To Load
var SchemaSet = new XmlSchemaSet();
//Add the file xsd file to the path
SchemaSet.Add(TargetNamespace, SchemaFileLocation);
//Compile The Schema
SchemaSet.Compile();
//Return the XMLSchemaSet
return SchemaSet;
}
示例11: CreateSchema
private static XmlSchemaSet CreateSchema()
{
var schemas = new XmlSchemaSet { XmlResolver = new ResourceXmlResolver() };
schemas.Add(DDEXSchemaLoader.LoadSchema("release-notification.xsd"));
schemas.Compile();
return schemas;
}
示例12: GenerateMapping
public ClrMappingInfo GenerateMapping(XmlSchemaSet schemas)
{
if (schemas == null)
{
throw new ArgumentNullException("schemas");
}
schemas.ValidationEventHandler += new ValidationEventHandler(Validationcallback);
schemas.Compile();
this.schemas = schemas;
if (schemaErrorCount > 0)
{
Console.WriteLine("Schema cannot be compiled. Class generation aborted");
return null;
}
// Execute transformations
try
{
Xml.Fxt.FxtLinq2XsdInterpreter.Run(schemas, configSettings.trafo);
}
catch (Xml.Fxt.FxtException)
{
Console.WriteLine("Schema cannot be transformed. Class generation aborted");
return null;
}
return GenerateMetaModel();
}
示例13: ValidXmlDoc
public void ValidXmlDoc(string xml, XmlReader xsd)
{
if (string.IsNullOrEmpty(xml))
{
throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "The argument '{0}' is Null or Empty", "xml"));
}
if (xsd == null)
{
throw new ArgumentNullException("xsd");
}
try
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add(null, xsd);
sc.Compile();
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader reader;
using (StringReader stringReader = new StringReader(xml))
{
reader = XmlReader.Create(stringReader, settings);
while (reader.Read());
}
}
catch (Exception ex)
{
this.validationError = ex.Message;
isValidXml = false;
}
}
示例14: CoreGetSourceObject
protected override object CoreGetSourceObject(string sourceFilePath, IDictionary<string, IList<string>> properties)
{
XmlSchemaSet xmlSchemaSet;
XmlSchema xmlSchema;
ObjectConstruct objectConstruct00;
if ((object)sourceFilePath == null)
throw new ArgumentNullException("sourceFilePath");
if ((object)properties == null)
throw new ArgumentNullException("properties");
if (DataType.IsWhiteSpace(sourceFilePath))
throw new ArgumentOutOfRangeException("sourceFilePath");
sourceFilePath = Path.GetFullPath(sourceFilePath);
objectConstruct00 = new ObjectConstruct();
using (Stream stream = File.Open(sourceFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
xmlSchema = XmlSchema.Read(stream, ValidationCallback);
xmlSchemaSet = new XmlSchemaSet();
xmlSchemaSet.Add(xmlSchema);
xmlSchemaSet.Compile();
xmlSchema = xmlSchemaSet.Schemas().Cast<XmlSchema>().ToList()[0];
EnumSchema(objectConstruct00, xmlSchema.Items);
return objectConstruct00;
}
示例15: Add
public void Add ()
{
XmlSchemaSet ss = new XmlSchemaSet ();
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
ss.Add (null, new XmlNodeReader (doc)); // null targetNamespace
ss.Compile ();
// same document, different targetNamespace
ss.Add ("ab", new XmlNodeReader (doc));
// Add(null, xmlReader) -> targetNamespace in the schema
doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:foo' />");
ss.Add (null, new XmlNodeReader (doc));
Assert.AreEqual (3, ss.Count);
bool chameleon = false;
bool ab = false;
bool urnfoo = false;
foreach (XmlSchema schema in ss.Schemas ()) {
if (schema.TargetNamespace == null)
chameleon = true;
else if (schema.TargetNamespace == "ab")
ab = true;
else if (schema.TargetNamespace == "urn:foo")
urnfoo = true;
}
Assert.IsTrue (chameleon, "chameleon schema missing");
Assert.IsTrue (ab, "target-remapped schema missing");
Assert.IsTrue (urnfoo, "target specified in the schema ignored");
}