public bool xmlValidatorFromDTD(string xmlPath) { //creazione del doc con trattamento spazi bianchi XmlDocument doc = new XmlDocument(); BusinessLogic.Interoperabilità.InteropResolver my = new BusinessLogic.Interoperabilità.InteropResolver(); XmlTextReader xtr = new XmlTextReader(xmlPath); xtr.WhitespaceHandling = WhitespaceHandling.None; XmlValidatingReader xvr = new XmlValidatingReader(xtr); xvr.ValidationType = System.Xml.ValidationType.DTD; xvr.EntityHandling = System.Xml.EntityHandling.ExpandCharEntities; xvr.XmlResolver = my; bool esito = true; try { doc.Load(xvr); } catch (System.Xml.Schema.XmlSchemaException e) { logger.Debug("Errore nella validazione del file segnatura.XML: Eccezione:" + e.Message); esito = false; } finally { xvr.Close(); xtr.Close(); } return(esito); }
/// <summary> /// /// </summary> /// <param name="v"></param> /// <returns></returns> public bool xmlValidatorFromDTD(XmlDocument document) { bool retValue = false; using (MemoryStream stream = new MemoryStream()) { // Save del contenuto xml in un oggetto MemoryStream document.Save(stream); stream.Position = 0; //creazione del doc con trattamento spazi bianchi BusinessLogic.Interoperabilità.InteropResolver my = new BusinessLogic.Interoperabilità.InteropResolver(); XmlTextReader xtr = new XmlTextReader(stream); xtr.WhitespaceHandling = WhitespaceHandling.None; XmlValidatingReader xvr = new XmlValidatingReader(xtr); xvr.ValidationType = System.Xml.ValidationType.DTD; xvr.EntityHandling = System.Xml.EntityHandling.ExpandCharEntities; xvr.XmlResolver = my; XmlDocument doc = new XmlDocument(); try { doc.Load(xvr); retValue = true; } catch (System.Xml.Schema.XmlSchemaException e) { logger.Debug("Errore nella validazione del file segnatura.XML: Eccezione:" + e.Message); retValue = false; } finally { xvr.Close(); xtr.Close(); } } return(retValue); }