本文整理汇总了C#中System.Xml.XmlNodeReader类的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeReader类的具体用法?C# XmlNodeReader怎么用?C# XmlNodeReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlNodeReader类属于System.Xml命名空间,在下文中一共展示了XmlNodeReader类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Xml;
using System.Xml.Schema;
using System.IO;
public class Sample {
public static void Main() {
// Create and load the XML document.
XmlDocument doc = new XmlDocument();
doc.Load("booksSchema.xml");
// Make changes to the document.
XmlElement book = (XmlElement) doc.DocumentElement.FirstChild;
book.SetAttribute("publisher", "Worldwide Publishing");
// Create an XmlNodeReader using the XML document.
XmlNodeReader nodeReader = new XmlNodeReader(doc);
// Set the validation settings on the XmlReaderSettings object.
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add("urn:bookstore-schema", "books.xsd");
settings.ValidationEventHandler += new ValidationEventHandler (ValidationCallBack);
// Create a validating reader that wraps the XmlNodeReader object.
XmlReader reader = XmlReader.Create(nodeReader, settings);
// Parse the XML file.
while (reader.Read());
}
// Display any validation errors.
private static void ValidationCallBack(object sender, ValidationEventArgs e) {
Console.WriteLine("Validation Error: {0}", e.Message);
}
}