日期:2014-05-18 浏览次数:21131 次
XmlReader reader = null; XmlReaderSettings settings = new XmlReaderSettings(); settings.ValidationType = ValidationType.Schema; settings.IgnoreComments = true; settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation; settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings; settings.ValidationEventHandler += new ValidationEventHandler(this.ValidationCallBack); reader = XmlReader.Create(你的文件, settings); while (reader.Read()) { ...... } private void ValidationCallBack(object sender, ValidationEventArgs args) { XmlReader reader = (XmlReader)sender; if (args.Severity == XmlSeverityType.Warning) { Console.WriteLine(string.Format("***Warning: {0}\n", args.Message)); } else { Console.WriteLine(string.Format("***Error: {0}\n", args.Message)); } Console.WriteLine(string.Format("***Value: {0}\n", reader.Value)); Console.WriteLine(string.Format("***LineNumber: {0}\n", args.Exception.LineNumber)); }