////////////////////////////////////////////////////////////////////////////////
//Author: stardicky //
//E-mail: stardicky@hotmail.com //
//QQNumber: 9531511 //
//CompanyName: Ezone International //
//Class: HBS-0308 //
//title: 关于XML文档模型的事件驱动 //
////////////////////////////////////////////////////////////////////////////////
using System;
using System.XML;
namespace EzoneXMLEventDemo
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class XMLEvent
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//
XMLDocument XMLDoc=new XMLDocument();
XMLDeclaration MyDeclaration=XMLDoc.CreateXMLDeclaration("1.0","utf-8","yes");
XMLDoc.NodeChanged+=new XMLNodeChangedEventHandler(XMLDoc_NodeChanged);
XMLDoc.NodeChanging+=new XMLNodeChangedEventHandler(XMLDoc_NodeChanging);
XMLDoc.NodeInserted+=new XMLNodeChangedEventHandler(XMLDoc_NodeInserted);
XMLDoc.NodeInserting+=new XMLNodeChangedEventHandler(XMLDoc_NodeInserting);
XMLDoc.NodeRemoved+=new XMLNodeChangedEventHandler(XMLDoc_NodeRemoved);
XMLDoc.NodeRemoving+=new XMLNodeChangedEventHandler(XMLDoc_NodeRemoving);
XMLDoc.AppendChild(MyDeclaration);
XMLElement EzoneRoot=XMLDoc.CreateElement("EzoneRoot");
XMLDoc.AppendChild(EzoneRoot);
XMLElement MyName=XMLDoc.CreateElement("Name");
XMLElement FirstName=XMLDoc.CreateElement("First");
FirstName.InnerText="A";
XMLElement MiddleName=XMLDoc.CreateElement("Middle");
MiddleName.InnerText="B";
XMLElement LastName=XMLDoc.CreateElement("Last");
LastName.InnerText="C";
XMLDoc.DocumentElement.AppendChild(MyName);
MyName.AppendChild(FirstName);
MyName.AppendChild(MiddleName);
MyName.AppendChild(LastName);
Console.WriteLine(XMLDoc.InnerXML);
}
private static void XMLDoc_NodeChanged(object sender, XMLNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XMLDoc_NodeChanged");
Console.WriteLine("事件类型: "+e.Action.ToString());
Console.WriteLine("节点类型: "+e.Node.NodeType.ToString());
Console.WriteLine("节点名称: "+e.Node.Name);
Console.WriteLine("节点的值: "+e.Node.InnerXML);
Console.WriteLine("-------------------------------------------------------");
}
private static void XMLDoc_NodeChanging(object sender, XMLNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XMLDoc_NodeChanging");
Console.WriteLine("事件类型: "+e.Action.ToString());
Console.WriteLine("节点类型: "+e.Node.NodeType.ToString());
Console.WriteLine("节点名称: "+e.Node.Name);
Console.WriteLine("节点的值: "+e.Node.InnerXML);
Console.WriteLine("-------------------------------------------------------");
}
private st