locked
XmlException with XmlSchema.Read RRS feed

  • Question

  • Hi, using C# I am getting an Exception and I cannot figure out why.
    try
    {
       _schema  = XmlSchema.Read( File.OpenRead( schemaFile ), new ValidationEventHandler( SchemaValidateError ) );
    }
    catch( XmlException e )
    {
       Console.WriteLine( "XmlException caught: " + e.Message );
    }
    SchemaValidateError is has signature void SchemaValidateError( object, ValidationEventArgs ) but it is not being called.
    I have a valid *.xsd file that i have since modified: changing </xs:schema> ti </xs:schemas> and it throws the XmlException. The online documents say it only throws an exception if the ValidationEventHandler is not specified. Any Ideas? Or any way i could change my *.xsd to make it go into the other method (SchemaValidateError) ?
    • Moved by nobugz Tuesday, June 2, 2009 8:30 PM (From:.NET Base Class Library)
    Tuesday, June 2, 2009 7:24 PM

Answers

  • If you change </xs:schema> to </xs:schemas> then your schema is no longer a well-formed XML document and the XML parser will give an XmlException. The ValidationEventHandler is only called for validation problems, not for well-formedness violations.
    MVP XML My blog
    Wednesday, June 3, 2009 10:49 AM