本文整理汇总了C#中System.Xml.Schema.XmlSchemaSet.Add方法的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaSet.Add方法的具体用法?C# XmlSchemaSet.Add怎么用?C# XmlSchemaSet.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Schema.XmlSchemaSet
的用法示例。
在下文中一共展示了XmlSchemaSet.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetXml
public string GetXml(bool validate)
{
XNamespace ns = "http://sd.ic.gc.ca/SLDR_Schema_Definition_en";
var spectrum_licences = getLicences();
XDocument doc = new XDocument(new XElement("spectrum_licence_data_registry", spectrum_licences));
foreach (XElement e in doc.Root.DescendantsAndSelf())
{
if (e.Name.Namespace == "")
e.Name = ns + e.Name.LocalName;
}
var errors = new StringBuilder();
if (validate)
{
XmlSchemaSet set = new XmlSchemaSet();
var schema = getMainSchema();
set.Add(null, schema);
doc.Validate(set, (sender, args) => { errors.AppendLine(args.Message); });
}
//return errors.Length > 0 ? errors.ToString() : doc.ToString();
var result = errors.Length > 0 ? "Validation Errors: " + errors.ToString() : getDocumentAsString(doc);
return result;
}
示例2: 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");
#if USE_DATA_CONTRACT_IMPORTER
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);
dc_importer.Import (schema_set_in_use);
#endif
this.importer = importer;
this.context = context;
try {
DoImportContract ();
} finally {
this.importer = null;
this.context = null;
}
}
示例3: 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);
}
示例4: 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;
}
}
示例5: IsValidMessage
internal static bool IsValidMessage(XDocument doc, XDocument schema)
{
var schemas = new XmlSchemaSet();
schemas.Add("http://www.SDMX.org/resources/SDMXML/schemas/v2_0/message",
GetPath("lib\\SDMXMessage.xsd"));
if (schema != null)
{
using (var reader = schema.CreateReader())
{
schemas.Add(null, reader);
}
}
bool isValid = true;
doc.Validate(schemas, (s, args) =>
{
isValid = false;
if (args.Severity == XmlSeverityType.Warning)
Console.WriteLine("\tWarning: " + args.Message);
else
Console.WriteLine("\tError: " + args.Message);
});
return isValid;
}
示例6: 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);
}
示例7: 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");
}
示例8: AddTwice
public void AddTwice ()
{
XmlSchemaSet ss = new XmlSchemaSet ();
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
ss.Add ("ab", new XmlNodeReader (doc));
ss.Add ("ab", new XmlNodeReader (doc));
}
示例9: v3
public void v3()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("xsdauthor", TestData._XsdAuthor);
sc.Add(null, TestData._Root + "xsdbookexternal.xsd");
CError.Compare(sc.Count, 2, "Count");
return;
}
示例10: SchemaCache
/// <summary>
/// Prevents a default instance of the <see cref="SchemaCache"/> class from being created.
/// Initialize a new instance of the <see cref="SchemaCache"/> class
/// </summary>
private SchemaCache()
{
var schemaSet = new XmlSchemaSet();
schemaSet.ValidationEventHandler -= this.SchemaSetValidationEventHandler;
schemaSet.ValidationEventHandler += this.SchemaSetValidationEventHandler;
schemaSet.Add(this.LoadXsdFromResource(GetSoapXsdLocation(SoapProtocolVersion.Soap11)));
schemaSet.Add(this.LoadXsdFromResource(GetSoapXsdLocation(SoapProtocolVersion.Soap12)));
this._soapSchema = schemaSet;
this._soapSchema.Compile();
}
示例11: AddSchemaThenReader
public void AddSchemaThenReader ()
{
XmlSchemaSet ss = new XmlSchemaSet ();
XmlDocument doc = new XmlDocument ();
doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />");
XmlSchema xs = new XmlSchema ();
xs.TargetNamespace = "ab";
ss.Add (xs);
ss.Add ("ab", new XmlNodeReader (doc));
}
示例12: v2
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("xsdauthor", TestData._XsdNoNs);
sc.Add("xsdauthor", TestData._XsdAuthor);
CError.Compare(sc.Count, 2, "Count");
return;
}
示例13: v4
//[Variation(Desc = "v4 - sc = self", Priority = 0)]
public void v4()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("xsdauthor", TestData._XsdAuthor);
sc.Add(sc);
Assert.Equal(sc.Count, 1);
return;
}
示例14: v2
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
XmlSchema Schema1 = sc.Add("xsdauthor1", TestData._XsdNoNs);
XmlSchema Schema2 = sc.Add("xsdauthor", TestData._XsdAuthor);
ICollection Col = sc.Schemas();
CError.Compare(Col.Count, 2, "Count");
return;
}
示例15: SchemasFromDescrip
public static XmlSchemaSet SchemasFromDescrip(IEnumerable<ServiceDescription> descriptions)
{
var schemaSet = new XmlSchemaSet();
var soap = new StringReader(string.Format(Properties.Resources.SoapSchema, descriptions.First().TargetNamespace));
schemaSet.Add(XmlSchema.Read(soap, new ValidationEventHandler(Validation)));
foreach (var schema in descriptions.SelectMany(d => d.Types.Schemas.OfType<XmlSchema>()))
{
schemaSet.Add(schema);
}
schemaSet.Compile();
return schemaSet;
}