/// <summary> /// Validate XML for its Type name (root node name normally). /// </summary> /// <param name="xml">XmlDocument object, ProviderRequest xml.</param> /// <param name="typeName">string, The type name of XML object. eg. "ProviderRequest"</param> /// <returns>String the validation message if failed else empty string.</returns> public static string Validate(XmlDocument xml, string typeName, log4net.Ext.Serializable.SLog logger, log4net.helpers.PropertiesCollectionEx loggerProp) { _sb = new StringBuilder(string.Empty); try { //Get Schema Assembly Assembly ass = GetSchemaAssembly(); //get the type only match the typeName, eg. "ProviderRequest" Type t = ass.GetTypes().FirstOrDefault(x => x.Name.Equals(typeName, StringComparison.OrdinalIgnoreCase)); //Add the found schema into XmlSchemaSet if (t != null) { XmlSchema s = (Activator.CreateInstance(t) as SchemaBase).Schema; xml.Schemas.Add(s); } //Type[] ts = ass.GetTypes(); //foreach (Type t in ts) //{ // if (t.Name == "ProviderRequest") // { // XmlSchema s = (Activator.CreateInstance(t) as SchemaBase).Schema; // xmlSet.Add(s); // xml.Schemas.Add(s); // } // //string fn = t.FullName; //} xml.Validate(new ValidationEventHandler(ValidationHandler)); } catch (Exception ex) { logger.Error(loggerProp, "Error XmlHelper.Validate " + ex.ToString()); throw ex; } string result = _sb.ToString().Trim(); return(result); }
public CustomXmlValidator() { //Use a different registry key (subkey of normal log4net key) so we can initialize a separate logger without locking all the other logger files log4net.Ext.Serializable.SLog sLogger = null; // LogManager.Initialise(Constants.AffiliateApplicationName, Constants.Logger.ReceiveLogger, null); _logger = (ILog)sLogger; }