////////////////////////////////////////////////////////////////////////////////
//Author: stardicky //
//E-mail: [email protected] //
//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 static void XmlDoc_NodeInserted(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XmlDoc_NodeInserted");
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_NodeInserting(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XmlDoc_NodeInserting");
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_NodeRemoved(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XmlDoc_NodeRemoved");
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_NodeRemoving(object sender, XmlNodeChangedEventArgs e)
{
Console.WriteLine("-------------------------------------------------------");
Console.WriteLine("产生事件 - XmlDoc_NodeRemoving");
Console.WriteLine("事件类型: "+e.Action.ToString());
Console.WriteLine("节点类型: "+e.Node.NodeType.ToString());
Console.WriteLine("节点名称: "+e.Node.Name);
Console.WriteLine("节点的值: "+e.Node.InnerXml);
Console.WriteLine("-------------------------------------------------------");
}
}
}
//(程序运行结果)
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: XmlDeclaration
//节点名称: xml
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: XmlDeclaration
//节点名称: xml
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Element
//节点名称: EzoneRoot
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Element
//节点名称: EzoneRoot
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Text
//节点名称: #text
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Element
//节点名称: Name
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Element
//节点名称: Name
//节点的值:
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Element
//节点名称: First
//节点的值: A
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Element
//节点名称: First
//节点的值: A
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Element
//节点名称: Middle
//节点的值: B
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Element
//节点名称: Middle
//节点的值: B
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserting
//事件类型: Insert
//节点类型: Element
//节点名称: Last
//节点的值: C
//-------------------------------------------------------
//-------------------------------------------------------
//产生事件 - XmlDoc_NodeInserted
//事件类型: Insert
//节点类型: Element
//节点名称: Last
//节点的值: C
//-------------------------------------------------------
//<?xml version="1.0" encoding="utf-8" standalone="yes"?><EzoneRoot><Name><First>A
//</First><Middle>B</Middle><Last>C</Last></Name></EzoneRoot>
本文地址:http://com.8s8s.com/it/it44777.htm