/// <summary> /// Schema validator /// </summary> /// <param name="documentAsString">document to validate</param> public void Validate(string documentAsString) { this.logger.Trace("Schema validate xml document."); try { if (documentAsString == null) { throw new SchemaValidationInterceptionEmptyBodyException(); } XmlDataDocument xmlDoc = new XmlDataDocument(); xmlDoc.LoadXml(documentAsString); // ny udfording, find documentType via XmlReader eller ren string ? DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(xmlDoc); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet XmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); SchemaValidator schemaValidator = new SchemaValidator(); ValidationEventHandler validationEventHandler = new ValidationEventHandler(ValidationCallBack); schemaValidator.SchemaValidateXmlDocument(documentAsString, XmlSchemaSet, validationEventHandler); } } catch (SchemaValidateDocumentFailedException ex) { this.logger.Debug("Schema validate xml document.", ex); throw ex; } catch (SchemaValidationFailedException ex) { this.logger.Debug("Schema validate xml document.", ex); throw ex; } catch (Exception ex) { this.logger.Error("Schema validate xml document.", ex); throw new SchemaValidateDocumentFailedException(ex); } this.logger.Trace("Schema validate xml document - Finish."); }
public void Validate(XmlDocument document) { this.logger.Trace("Schema validate xml document."); try { if (document == null) { throw new SchemaValidationInterceptionEmptyBodyException(); } DocumentTypeConfig documentType = searcher.FindUniqueDocumentType(document); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet XmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); SchemaValidator schemaValidator = new SchemaValidator(); ValidationEventHandler validationEventHandler = new ValidationEventHandler(ValidationCallBack); schemaValidator.SchemaValidateXmlDocument(document, XmlSchemaSet, validationEventHandler); } } catch (SchemaValidateDocumentFailedException) { throw; } catch (SchemaValidationFailedException) { throw; } catch (Exception ex) { this.logger.Debug("Schema validate xml document.", ex); throw new SchemaValidateDocumentFailedException(ex); } this.logger.Trace("Schema validate xml document - Finish."); }
private void Validate(string xmlDocumentPath, SchemaValidator validator, string schemaPath) { // Need the schema cache from the cacheConfiguration ConfigurationHandler.ConfigFilePath = "Resources/RaspConfiguration.Live.xml"; ConfigurationHandler.Reset(); XmlDocument document = new XmlDocument(); document.Load(xmlDocumentPath); DocumentTypeConfig documentType = _searcher.FindUniqueDocumentType(document); if (string.IsNullOrEmpty(documentType.SchemaPath)) { // Empty schema path equal no schema exist. } else { SchemaStore schemaStore = new SchemaStore(); XmlSchemaSet xmlSchemaSet = schemaStore.GetCompiledXmlSchemaSet(documentType); validator.SchemaValidateXmlDocument(document, xmlSchemaSet); } }