本文整理汇总了C#中System.Xml.XmlNodeChangedEventHandler代理的典型用法代码示例。如果您正苦于以下问题:C# XmlNodeChangedEventHandler代理的具体用法?C# XmlNodeChangedEventHandler怎么用?C# XmlNodeChangedEventHandler使用的例子?那么恭喜您, 这里精选的代理代码示例或许可以为您提供帮助。
XmlNodeChangedEventHandler代理属于System.Xml命名空间,在下文中一共展示了XmlNodeChangedEventHandler代理的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml;
namespace Microsoft.Samples.Xml
{
public class Sample
{
private const String filename = "book.xml";
public static void Main()
{
Sample mySample = new Sample();
mySample.Run(filename);
}
public void Run(String args)
{
// Create and load the XML document.
Console.WriteLine("Loading file {0} ...", args);
XmlDocument doc = new XmlDocument();
doc.Load(args);
//Create the event handlers.
doc.NodeChanged += new XmlNodeChangedEventHandler(this.MyNodeChangedEvent);
doc.NodeInserted += new XmlNodeChangedEventHandler(this.MyNodeInsertedEvent);
// Change the book price.
doc.DocumentElement.LastChild.InnerText = "5.95";
// Add a new element.
XmlElement newElem = doc.CreateElement("style");
newElem.InnerText = "hardcover";
doc.DocumentElement.AppendChild(newElem);
Console.WriteLine("\r\nDisplay the modified XML...");
Console.WriteLine(doc.OuterXml);
}
// Handle the NodeChanged event.
private void MyNodeChangedEvent(Object source, XmlNodeChangedEventArgs args)
{
Console.Write("Node Changed Event: <{0}> changed", args.Node.Name);
if (args.Node.Value != null)
{
Console.WriteLine(" with value {0}", args.Node.Value);
}
else
{
Console.WriteLine("");
}
}
// Handle the NodeInserted event.
private void MyNodeInsertedEvent(Object source, XmlNodeChangedEventArgs args)
{
Console.Write("Node Inserted Event: <{0}> inserted", args.Node.Name);
if (args.Node.Value != null)
{
Console.WriteLine(" with value {0}", args.Node.Value);
}
else
{
Console.WriteLine("");
}
}
} // End class