Validating an XML against referenced XSD in C#

后端 未结 5 663
天命终不由人
天命终不由人 2020-11-22 13:33

I have an XML file with a specified schema location such as this:

xsi:schemaLocation=\"someurl ..\\localSchemaPath.xsd\"

I want to validate

5条回答
  •  情深已故
    2020-11-22 14:14

    I had do this kind of automatic validation in VB and this is how I did it (converted to C#):

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ValidationType = ValidationType.Schema;
    settings.ValidationFlags = settings.ValidationFlags |
                               Schema.XmlSchemaValidationFlags.ProcessSchemaLocation;
    XmlReader XMLvalidator = XmlReader.Create(reader, settings);
    

    Then I subscribed to the settings.ValidationEventHandler event while reading the file.

提交回复
热议问题