如何从XSD获取XmlSchema对象,这是C#中的字符串?

eom*_*off 11 c# xml string xsd

如何从包含所有XSD内容的大字符串中获取XmlSchema对象?

tma*_*hey 23

Read方法是静态的.所以更好用

XmlSchema schema = XmlSchema.Read(
    schemaReader, (sender, args) =>
    {
         // HANDLE VALIDATION FAILED
    });                                                                        
Run Code Online (Sandbox Code Playgroud)


Fré*_*idi 11

您可以使用StringReader:

string content = ".......";
XmlSchema schema = new XmlSchema();
schema.Read(new StringReader(content), ValidateSchema);
Run Code Online (Sandbox Code Playgroud)

  • 确切地说,如果在尝试使用此模式验证xml时内容包含标记,那么它将失败,因为您必须首先添加所有包含然后最多的父xsd,这在使用URI时不是这种情况.谢谢. (2认同)