[英]The xsd.exe generated C# class from the W3C XMLschema.xsd (the schema for xsd validation) is not accepted by the C# XmlSerializer
[英]How to get XmlSchema object from XSD which is string in C#?
如何從包含所有 XSD 內容的大字符串中獲取 XmlSchema 對象?
Read 方法是靜態的。 所以更好地使用
XmlSchema schema = XmlSchema.Read(
schemaReader, (sender, args) =>
{
// HANDLE VALIDATION FAILED
});
您可以使用StringReader :
string content = ".......";
XmlSchema schema = new XmlSchema();
schema.Read(new StringReader(content), ValidateSchema);
string xsdContent = "...";
string xmlContent = "...";
XmlSchemaSet schema;
XDocument xmlDoc;
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xsdContent)))
{
var xsc = XmlSchema.Read(ms, (o, e) =>
{
Error.SetWarning($"XML Schema error: {e.Message}");
});
schema = new XmlSchemaSet();
schema.Add(xsc);
xmlDoc = XDocument.Parse(xmlContent, LoadOptions.SetLineInfo);
}
xmlDoc.Validate(schema, (o, e) =>
{
// handle validation errors
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.