/// <summary> /// Pulls an XSD file from an application resource and uses it to /// verify whether submitted XML file in filesystem is valid or not /// </summary> /// <param name="sXML">XML file to validate</param> /// <returns>Error message (if any). Returns string with zero length /// if everythings fine.</returns> private static List <string> TestXML(string sXML) { string sAssembly = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; // Replace the information in '<>' brackets with a valid path // to a XSD file (that you added into your Visual Studio project) // Be careful: Names are case sensitiv and '.' are delimters. // Make sure your XSD file is an 'embedded resource' // "<Namespace>.<FolderName>.<Filename>.xsd" const string XSD_Location = "ICSharpCode.AvalonEdit.Highlighting.Themes.XML.HlTheme.xsd"; SchemaValidator vs = new SchemaValidator(); Assembly a = Assembly.LoadFrom(sAssembly); using (Stream strm = a.GetManifestResourceStream(XSD_Location)) { if (strm == null) { List <string> l = new List <string>(); l.Add(string.Format(CultureInfo.InvariantCulture, "Unable to load XSD: '{0}' file from internal resource.", XSD_Location)); return(l); } vs.CheckXML_XSD(sXML, strm); if (vs.IsSchemaValid == false) // Return strings describing problems (if any) { return(vs.ErrorMessages); } } return(null); }
/// <summary> /// Pulls an XSD file from an application resource and uses it to /// verify whether submitted XML file in filesystem is valid or not /// </summary> /// <param name="sXML">XML file to validate</param> /// <returns>Error message (if any). Returns string with zero length /// if everythings fine.</returns> private static List<string> TestXML(string sXML) { string sAssembly = System.Reflection.Assembly.GetExecutingAssembly().CodeBase; // Replace the information in '<>' brackets with a valid path // to a XSD file (that you added into your Visual Studio project) // Be careful: Names are case sensitiv and '.' are delimters. // Make sure your XSD file is an 'embedded resource' // "<Namespace>.<FolderName>.<Filename>.xsd" const string XSD_Location = "ICSharpCode.AvalonEdit.Highlighting.Themes.XML.HlTheme.xsd"; SchemaValidator vs = new SchemaValidator(); Assembly a = Assembly.LoadFrom(sAssembly); using (Stream strm = a.GetManifestResourceStream(XSD_Location)) { if (strm == null) { List<string> l = new List<string>(); l.Add(string.Format(CultureInfo.InvariantCulture, "Unable to load XSD: '{0}' file from internal resource.", XSD_Location)); return(l); } vs.CheckXML_XSD(sXML, strm); if (vs.IsSchemaValid == false) // Return strings describing problems (if any) return vs.ErrorMessages; } return null; }