日期:2014-05-18 浏览次数:20845 次
XmlReaderSettings settings = new XmlReaderSettings(); //添加模式 settings.Schemas.Add(null, @"..\..\books.xsd"); //在读取时执行验证 settings.ValidationType = ValidationType.Schema; //不处理异常,而是显示验证失败信息 settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler); //创建含有XmlReaderSettings对象的XmlReader读取器 XmlReader reader = XmlReader.Create(@"..\..\books.xml", settings); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Text) { Console.WriteLine(reader.Value); } } Console.ReadLine();