C # Operation XML Preliminary (8) Chapter 4: General XML Processing Method (2) Previous, we provide a class to operate XML files, here is an example of an application, an XML written by boring time The message code for message data is as follows: use system;
Using system.io;
Using system.data;
Using system.diagnostics;
Using XMLbook.com.sem.tools; // This includes the class provided by the previous
Namespace XMLBOOK.COMPONENT
{
///
/// copyright: Copyright by SEM IT Department
/// version: 0.0.1
/// File: xmlbook.component.mdlDataMange.cs
/// Purpose: Message data related operations
/// Author: European Yuanning @ 2005-04-09
/// Mailbox: Outrace@soueast-motor.com
/// Modify:
/// summary>
Public Class MdldataManage
{
#Region private member
Private string strid = NULL;
Private string strname = null;
PRIVATE STRSEX = NULL;
Private string stremail = "no email";
Private string strpage = "no page";
Private string strqq= "no qq";
PRIVATE STRING STRSUBJECT = NULL;
PRIVATE STRING STRCONTENT = NULL;
Private string strreply = "no reply";
Private string strfilter = null;
#ndregion
#Region public member
///
/// Name
/// summary>
Public String Strname
{
Get {return this.strname;}
Set {this.strname = value;
}
///
/// gender
/// summary>
Public String Strsex
{
Get {return this.strsex;}
Set {this.strsex = value;
}
///
/// mailbox
/// summary>
Public String Stremail
{
Get {return this.streme;}
Set {this.stremail = value;
}
///
//// home page
/// summary>
Public String Strpage, PUBLIC STRPAGE
{
Get {return this.strpage;
Set {this.strpage = value;
}
///
/// OICQ number
/// summary>
Public String STRQQ
{
Get {return this.STRQQ;} set {this.strqq = value;
}
///
/// Theme
/// summary>
Public String strsubject
{
Get {return this.strsubject;
Set {this.strsubject = value;
}
///
/// content
/// summary>
Public String StrContent
{
Get {return this.strContent;
Set {this.strContent = value;
}
///
/// Reply
/// summary>
Public String Strreply
{
Get {return this.strreply;
Set {this.strreply = value;
}
///
/// ID number
/// summary>
Public String Strid
{
Get {return this.strid;}
Set {this.strid = value;
}
Public String Strfilter
{
Get {return this.strfilter;}
Set {this.strfilter = value;
}
#ndregion
Public mdldataManage ()
{
//
// Todo: Message data related operations
//
}
///
/// Add a message (here you demonstrate how to add a record)
/// summary>
Public void add ()
{
String [] arrfileds = new string [10];
String [] Arrvalues = new string [10];
Arrfileds [0] = "ID";
Arrfileds [1] = "Name";
Arrfileds [2] = "SEX";
Arrfileds [3] = "email";
Arrfileds [4] = "Page";
Arrfileds [5] = "QQ";
Arrfileds [6] = "Subject";
Arrfileds [7] = "Content";
Arrfileds [8] = "reply";
Arrfileds [9] = "DateTime";
Arrvalues [0] = datetime.now.tofiletime (). Tostring ();
Arrvalues [1] = this.strname;
Arrvalues [2] = this.strsex;
Arrvalues [3] = this.stremail;
Arrvalues [4] = this.strpage;
Arrvalues [5] = this.STRQQ;
Arrvalues [6] = this.strsubject;
Arrvalues [7] = this.strcontent;
Arrvalues [8] = "no reply";
Arrvalues [9] = datetime.now.toString ();
Try
{
XmlDatabase XML = new xmldatabase (); xml.strdatafile = config.datafile;
Xml.strfields = arrfiled
Xml.strdata = arrvalues;
Xml.insert ();
Xml.clear ();
}
Catch (Exception EE)
{
LOG log = new log ();
Log.struser = "system";
Log.StrDepartment = "Sign Write Message";
Log.strfilename = "xmlbook.component.mdldataManage.cs";
Log.STRDESCRIPTION = EE.MESSAGE;
Log.writelog ();
}
}
///
/// Reply message (here you demonstrate how to modify a first XML record)
/// summary>
Public void reply ()
{
String [] arrfileds = new string [1];
String [] Arrvalues = New String [1];
Arrfileds [0] = "reply";
Arrvalues [0] = this.strreply;
Try
{
XmlDatabase XML = New XmLDatabase ();
Xml.strdatafile = config.datafile;
Xml.strdata = arrvalues;
Xml.strfields = arrfiled
Xml.Strfilter = "ID = '" this.strid "'";
Xml.Update ();
Xml.clear ();
}
Catch (Exception EE)
{
LOG log = new log ();
Log.struser = "system";
Log.StrDepartment = "Reply Data";
Log.strfilename = "xmlbook.component.mdldataManage.cs";
Log.STRDESCRIPTION = EE.MESSAGE;
Log.writelog ();
}
}
///
/// Delete message (here how to delete a record)
/// summary>
Public void delete ()
{
Try
{
XmlDatabase XML = New XmLDatabase ();
Xml.strdatafile = config.datafile;
Xml.Strfilter = "ID = '" this.strid "'";
Xml.delete ();
Xml.clear ();
}
Catch (Exception EE)
{
LOG log = new log ();
Log.struser = "system";
Log.StrDepartment = "Reply Data";
Log.strfilename = "xmlbook.component.mdldataManage.cs";
Log.StrDescription = Ee.Message; log.writelog ();
}
}
///
/// Get a few lines of message data (here the presentation gets a row or multi-line data)
/// summary>
///
Public DataRow [] getONerow ()
{
XmlDatabase XML = New XmLDatabase ();
DATAROW [] DR = NULL;
Try
{
Xml.strdatafile = config.datafile;
Xml.strfilter = this.strfilter;
DR = Xml.selectrows ();
Return DR;
}
Catch (Exception EE)
{
LOG log = new log ();
Log.struser = "system";
Log.StrDepartment = "Get a line of data";
Log.strfilename = "xmlbook.component.mdldataManage.cs";
Log.STRDESCRIPTION = EE.MESSAGE;
Log.writelog ();
Return DR;
}
Finally
{
Xml.clear ();
}
}
///
/// Get a view
/// summary>
///
Public DataView getView ()
{
XmlDatabase XML = New XmLDatabase ();
DataView DV = NULL;
Try
{
Xml.strdatafile = config.datafile;
Xml.strfilter = this.strfilter;
DV = Xml.selectView ();
Return DV;
}
Catch (Exception EE)
{
LOG log = new log ();
Log.struser = "system";
Log.StrDepartment = "Get View";
Log.strfilename = "xmlbook.component.mdldataManage.cs";
Log.STRDESCRIPTION = EE.MESSAGE;
Log.writelog ();
Return DV;
}
Finally
{
Xml.clear ();
}
}
}
}
It is hoped that you can provide a little reference to you through the above example. The serial load for XML file is here. If you feel some help you. Please take me away. I am also a rookie just learned, many ideas, practices are very naive, don't smile. One XML message mentioned in this article, if anyone needs the original code, please contact me, I have no space can be uploaded, everyone can send me an email: Outrace@soueast-motor.com. Multi-exchange