本文整理汇总了C#中System.Xml.Schema.XmlSchemaSet类的典型用法代码示例。如果您正苦于以下问题:C# XmlSchemaSet类的具体用法?C# XmlSchemaSet怎么用?C# XmlSchemaSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlSchemaSet类属于System.Xml.Schema命名空间,在下文中一共展示了XmlSchemaSet类的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: AddElementToSchema
void AddElementToSchema(XmlSchemaElement element, string elementNs, XmlSchemaSet schemaSet)
{
OperationDescription parentOperation = this.operation;
if (parentOperation.OperationMethod != null)
{
XmlQualifiedName qname = new XmlQualifiedName(element.Name, elementNs);
OperationElement existingElement;
if (ExportedMessages.ElementTypes.TryGetValue(qname, out existingElement))
{
if (existingElement.Operation.OperationMethod == parentOperation.OperationMethod)
return;
if (!SchemaHelper.IsMatch(element, existingElement.Element))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.CannotHaveTwoOperationsWithTheSameElement5, parentOperation.OperationMethod.DeclaringType, parentOperation.OperationMethod.Name, qname, existingElement.Operation.OperationMethod.DeclaringType, existingElement.Operation.Name)));
}
return;
}
else
{
ExportedMessages.ElementTypes.Add(qname, new OperationElement(element, parentOperation));
}
}
SchemaHelper.AddElementToSchema(element, SchemaHelper.GetSchema(elementNs, schemaSet), schemaSet);
}
示例3: ValidateXml
public bool ValidateXml(string inputXML, string xsdUri)
{
stringBuilder = new StringBuilder();
bool validated = false;
// Create the XmlSchemaSet class.
XmlSchemaSet sc = new XmlSchemaSet();
// Add the schema to the collection.
sc.Add(null, xsdUri);
// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ConformanceLevel = ConformanceLevel.Auto;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlTextReader reader = new XmlTextReader(new StringReader(inputXML));
while (reader.Read())
{ }
if (stringBuilder.ToString() == String.Empty)
validated = true;
return validated;
}
示例4: v2
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
try
{
XmlSchema Schema1 = sc.Add(null, TestData._XsdAuthor);
CError.Compare(sc.Count, 1, "AddCount");
CError.Compare(sc.Contains(Schema1), true, "AddContains");
CError.Compare(sc.IsCompiled, false, "AddIsCompiled");
XmlSchema Schema2 = XmlSchema.Read(new StreamReader(new FileStream(TestData._XsdNoNs, FileMode.Open, FileAccess.Read)), null);
sc.Compile();
CError.Compare(sc.Count, 1, "Compile");
CError.Compare(sc.Contains(Schema1), true, "Contains");
sc.Reprocess(Schema2);
CError.Compare(sc.Count, 1, "Reprocess");
CError.Compare(sc.Contains(Schema2), true, "Contains");
}
catch (ArgumentException e)
{
_output.WriteLine(e.ToString());
CError.Compare(sc.Count, 1, "AE");
return;
}
Assert.True(false);
}
示例5: IsXmlValid
public static bool IsXmlValid(string schemaFile, string xmlFile)
{
try
{
var valid = true;
var sc = new XmlSchemaSet();
sc.Add(string.Empty, schemaFile);
var settings = new XmlReaderSettings { ValidationType = ValidationType.Schema, Schemas = sc };
settings.ValidationEventHandler += delegate { valid = false; };
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
settings.IgnoreWhitespace = true;
var reader = XmlReader.Create(xmlFile, settings);
try
{
while (reader.Read()) {}
}
catch (XmlException xmlException)
{
Console.WriteLine(xmlException);
}
return valid;
}
catch
{
return false;
}
}
示例6: GetSchema
public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet)
{
if (xmlSchemaSet == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSchemaSet");
XmlQualifiedName eprType = EprType;
XmlSchema eprSchema = GetEprSchema();
ICollection schemas = xmlSchemaSet.Schemas(Addressing200408Strings.Namespace);
if (schemas == null || schemas.Count == 0)
xmlSchemaSet.Add(eprSchema);
else
{
XmlSchema schemaToAdd = null;
foreach (XmlSchema xmlSchema in schemas)
{
if (xmlSchema.SchemaTypes.Contains(eprType))
{
schemaToAdd = null;
break;
}
else
schemaToAdd = xmlSchema;
}
if (schemaToAdd != null)
{
foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray())
schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace);
foreach (XmlSchemaObject schemaObject in eprSchema.Items)
schemaToAdd.Items.Add(schemaObject);
xmlSchemaSet.Reprocess(schemaToAdd);
}
}
return eprType;
}
示例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: v2
//[Variation(Desc = "v2 - Contains with non existing ns", Priority = 0)]
public void v2()
{
XmlSchemaSet sc = new XmlSchemaSet();
sc.Add("xsdauthor", TestData._XsdAuthor);
Assert.Equal(sc.Contains("test"), false);
return;
}
示例9: 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();
}
示例10: Validate
private string Validate(string path)
{
var sc = new XmlSchemaSet();
string dir = @"..\..\..\..\Schemas\Collada\";
sc.Add("http://www.collada.org/2008/03/COLLADASchema", dir + "collada_schema_1_5.xsd");
return Validate(path, sc);
}
示例11: Import
public void Import(XmlSchemaSet schemas)
{
if (schemas == null)
throw System.Runtime.Serialization.DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("schemas"));
InternalImport(schemas, null, null, null);
}
示例12: validate
public bool validate()
{
try
{
XmlSchemaSet sc = new XmlSchemaSet();
// Add the schema to the collection.
sc.Add("urn:mites-schema", this.xsdFile);
// Set the validation settings.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas = sc;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
// Create the XmlReader object.
XmlReader reader = XmlReader.Create(this.xmlFile, settings);
// Parse the file.
while (reader.Read())
{
;
}
return true;
}
catch (Exception e)
{
throw new Exception("Error in (SXML.ConfigurationReader,validate):" + e.ToString());
}
}
示例13: IsValid
public bool IsValid(Stream template)
{
if (template == null)
{
throw new ArgumentNullException("template");
}
// Load the template into an XDocument
XDocument xml = XDocument.Load(template);
// Load the XSD embedded resource
Stream stream = typeof(XMLPnPSchemaV201508Formatter)
.Assembly
.GetManifestResourceStream("OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml.ProvisioningSchema-2015-08.xsd");
// Prepare the XML Schema Set
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_08,
new XmlTextReader(stream));
Boolean result = true;
xml.Validate(schemas, (o, e) =>
{
Diagnostics.Log.Error(e.Exception, "SchemaFormatter", "Template is not valid: {0}", e.Message);
result = false;
});
return (result);
}
示例14: ValidateSave
public void ValidateSave()
{
WorldEntity world = createTestWorld();
XElement xElement = WorldTransformer.Instance.ToXElement(world, TransformerSettings.WorldNamespace + "World");
xElement.Save("unittestsave.xml", SaveOptions.OmitDuplicateNamespaces);
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, "WorldSchema1.xsd");
XDocument xDocument = new XDocument(xElement);
xDocument.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
xDocument.Save("unittest2.xml", SaveOptions.OmitDuplicateNamespaces);
XElement x1 = new XElement(TransformerSettings.WorldNamespace + "Outer");
x1.Add(new XElement(TransformerSettings.WorldNamespace + "Inner"));
x1.Save("unittest3.xml", SaveOptions.OmitDuplicateNamespaces);
string val = "";
xDocument.Validate(schemaSet, (o, vea) => {
val += o.GetType().Name + "\n";
val += vea.Message + "\n";
}, true);
Assert.AreEqual("", val);
}
示例15: Main
public static void Main()
{
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("urn:catalogue", "..//..//xml/catalogue.xsd");
XDocument XmlDocument = XDocument.Load("..//..//xml/catalogue.xml");
List<string> errorMessages = new List<string>();
XmlDocument.Validate(schemas, (obj, error) =>
{
errorMessages.Add(error.Message);
});
IPrinter printer = new ConsolePrinter();
if (errorMessages.Count == 0)
{
printer.Print("Valid catalogue.xml");
}
else
{
printer.Print(errorMessages);
}
}