This Code reads records from the database and uses multiple layers to generate xml and generate files.
Clientdao. mtvxmldao Dao = new mtvxmldao ();
// Place user code here to initialize the page
Datatable dtagent = Dao. mtvxmlagent ("agent_list"). Tables [0];
For (int l = 0; L <dtagent. Rows. Count; l ++)
{
Datarow dragent = dtagent. Rows [l];
String [] strprokey = new string [1];
Strprokey [0] = "@ agentid ";
String [] strprovalue = new string [1];
Strprovalue [0] = dragent ["Number"]. tostring ();
Datatable dt = Dao. mtvxmlmtv ("mtvclassclient_xml", strprokey, strprovalue). Tables [0];
Datatable dt2 = Dao. mtvxmlmtv ("mtvclient_xml", strprokey, strprovalue). Tables [0];
Datatable dt1 = Dao. mtvxmlmtvclass ("musicclass_list"). Tables [0];
String [] type1 = new string [5];
Type1 [0] = "Mainland China ";
Type1 [1] = "Europe and America ";
Type1 [2] = "Japan and South Korea ";
Type1 [3] = "Hong Kong and Taiwan ";
Type1 [4] = "other ";
Xmldocument XD = new xmldocument (); // represents an XML document
Xmldeclaration xde; // indicates the XML declaration node: <? XML version = '1. 0'...?>
Xde = XD. createxmldeclaration ("1.0", null, null );
Xde. Encoding = "gb2312 ";
Xde. standalone = "yes ";
XD. appendchild (xde); // <? XML version = "1.0" encoding = "UTF-8" standalone = "yes"?> Generation ends
Xmlelement Xe = XD. createelement ("root"); // create a root element
XD. appendchild (xe); // The root element is created.
Xmlnode root = XD. selectsinglenode ("root"); // query <root>
Xmlelement kind = XD. createelement ("Kind"); // create an element under <root> <tree>
For (INT p = 0; P <5; P ++)
{
Xmlelement type = XD. createelement ("type"); // create an element under <root> <tree>
Type. setattribute ("name", type1 [p]); // specifies the attribute value.
// Type. innertext = "Bootstrap 1"; // specify the attribute text node
For (INT I = 0; I <DT. Rows. Count; I ++)
{
Datarow DR = DT. Rows [I];
// If (Dr ["type"]. tostring () = type1 [p])
//{
String A = Dr ["mtvclassid"]. tostring ();
String B = "";
String mtvclassid = "";
For (Int J = 0; j <dt1.rows. Count; j ++)
{
Datarow DR1 = dt1.rows [J];
If (A = DR1 ["ID"]. tostring ())
{
Mtvclassid = DR1 ["ID"]. tostring ();
B = DR1 ["classname"]. tostring ();
}
}
Xmlelement classname = XD. createelement ("class"); // create an element under <root> <tree>
Classname. setattribute ("name", B );
For (int K = 0; k <dt2.rows. Count; k ++)
{
Datarow DR2 = dt2.rows [k];
If (DR2 ["mtvclassid"]. tostring () = mtvclassid & DR2 ["type"]. tostring () = type1 [p])
{
Xmlelement MTV = XD. createelement ("MTV"); // create an element under <root> <tree>
// MTV. setattribute ("no", "1 ");
Xmlelement id = XD. createelement ("ID"); // create an element under <root> <tree>
Id. setattribute ("ID", DR2 ["ID"]. tostring ());
MTV. appendchild (ID );
Xmlelement name = XD. createelement ("name"); // create an element under <root> <tree>
Name. setattribute ("name", DR2 ["name"]. tostring ());
MTV. appendchild (name );
Xmlelement actors = XD. createelement ("actors"); // create an element under <root> <tree>
Actors. setattribute ("actors", DR2 ["actors"]. tostring ());
MTV. appendchild (actors );
Xmlelement Director = XD. createelement ("Director"); // create an element under <root> <tree>
Director. setattribute ("director", DR2 ["director"]. tostring ());
MTV. appendchild (Director );
Xmlelement introduction = XD. createelement ("Introduction"); // create an element under <root> <tree>
Introduction. setattribute ("Introduction", DR2 ["Introduction"]. tostring ());
MTV. appendchild (Introduction );
Xmlelement copyright = XD. createelement ("Copyright"); // create an element under <root> <tree>
Copyright. setattribute ("Copyright", DR2 ["Copyright"]. tostring ());
MTV. appendchild (copyright );
Xmlelement photo2 = XD. createelement ("photo2"); // create an element under <root> <tree>
Photo2.setattribute ("photo2", DR2 ["photo2"]. tostring ());
MTV. appendchild (photo2 );
Xmlelement megsize = XD. createelement ("megsize"); // create an element under <root> <tree>
Megsize. setattribute ("megsize", DR2 ["megsize"]. tostring ());
MTV. appendchild (megsize );
Xmlelement filename = XD. createelement ("FILENAME"); // create an element under <root> <tree>
Filename. setattribute ("FILENAME", DR2 ["FILENAME"]. tostring ());
MTV. appendchild (filename );
Classname. appendchild (MTV );
}
}
Type. appendchild (classname );
//}
}
Kind. appendchild (type );
}
// ------------------------------ Second category
Root. appendchild (kind); // subnode completion <tree>
Foreach (string name in system. io. directory. getfiles (server. mappath (". ") +" \ XML "," MTV _ "+ dragent [" Number "]. tostring () + "*. *"))
{
System. Io. file. Delete (name );
}
Datetime currenttime;
Currenttime = system. datetime. now;
Int year = currenttime. Year;
Int Monty = currenttime. month;
Int day = currenttime. Day;
Int hour = currenttime. hour;
Int minute = currenttime. minute;
String STR = "";
STR = year. tostring () + Monty. tostring () + day. tostring () + hour. tostring () + minute. tostring ();
String thetime = "XML \" + "MTV" + "_" + dragent ["Number"]. tostring () + "_" + STR + ". xml ";
XD. Save (server. mappath (thetime ));
}