本文整理匯總了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