.net - Xml Validation error: validating against empty schema set -
i getting error
the xmlschemaset on document either null or has no schemas in it. provide schema information before calling validate.
but have schema file located in location specified:
c:\invschema.xsd
there no specific namespace passed, set empty.
so, why getting error?
i need know if xml schema validated, validate function no return boolean value confirming it.
how can value
invimp.validate(evthandler)
?
below code:
private function validateschema() boolean try dim settings xmlreadersettings = new xmlreadersettings() settings.schemas.add("", "c:\invschema.xsd") settings.validationtype = validationtype.schema dim evthandler validationeventhandler = new validationeventhandler(addressof validationeventhandler) dim reader xmlreader = xmlreader.create(_filename, settings) dim invimp xmldocument = new xmldocument invimp.validate(evthandler) validateschema = true catch ex exception throw ex validateschema = false end try end function shared sub validationeventhandler(byval sender object, byval e validationeventargs) select case e.severity case xmlseveritytype.error library.log("schema validation failed error " & e.message, logtype.errorlog, importtype.invcimp) case xmlseveritytype.warning library.log("schema validation warning " & e.message, logtype.eventlog, importtype.invcimp) end select end sub
i think there 2 problems. event handler isn't getting added , xmlreader should used validate instead of separate xmldocument object:
private function validateschema() boolean try dim settings xmlreadersettings = new xmlreadersettings() settings.schemas.add("", "c:\invschema.xsd") settings.validationtype = validationtype.schema addhandler settings.validationeventhandler, addressof validationeventhandler dim reader xmlreader = xmlreader.create(_filename, settings) while reader.read 'triggers validation' loop catch ex exception throw ex end try return _valid end function
you should set member level boolean (_valid) in event handler. event handler called every schema violation found.
Comments
Post a Comment