The XML file name is bcastr. xml.
The structure is as follows:CopyCodeThe Code is as follows: <? XML version = "1.0" encoding = "UTF-8"?>
<Bcaster>
<Item id = "79" item_url = "picnews/img/u = 404630538,2075277077" link = "html/050/ai_20081017_50_53_79.html" itemtitle = "111111111111111111"/>
<Item id = "78" item_url = "picnews/img/index_04_01_06.jpg" link = "html/050/ai_20081017_50_53_78.html" itemtitle = "zengjia"/>
<Item id = "77" item_url = "picnews/img/bsxwf.jpg" link = "html/050/ai_20081017_50_53_77.html" itemtitle = "Graduate Department of China Pharmaceutical University"/>
<Item id = "76" item_url = "picnews/img/Jiangning Damen .jpg" link = "html/050/ai_20081017_50_53_76.html" itemtitle = ""/>
<Item id = "75" item_url = "picnews/img/Chinese Pharmaceutical University certification (perfect 22.16.jpg" link = "html/050/ai_20081017_50_53_75.html" itemtitle = "News test picture news"/>
</Bcaster>
Add node functions:Copy codeThe Code is as follows: // write the image news information to the XML file set of the image news player.
/// </Summary>
/// <Param name = "picpath"> image path </param>
/// <Param name = "htmlpath"> image news URL </param>
/// <Param name = "title"> title </param>
Public void writepicnewsxml (string picpath, string htmlpath, String title, string aid)
{
Xmldocument xmldoc;
Xmldoc = new xmldocument ();
Xmldoc. Load (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
Xmlnodelist xnl = xmldoc. selectsinglenode ("bcaster"). childnodes;
// If (xnl. Count <= 5) // keep no more than 5 homepage pictures and news
//{
Xmlnode rootnode = xmldoc. selectsinglenode ("bcaster ");
Xmlelement Fel = (xmlelement) rootnode. firstchild;
Xmlelement El = xmldoc. createelement ("item"); // Add subnodes and attributes
El. setattribute ("ID", aid );
El. setattribute ("item_url", picpath );
El. setattribute ("Link", htmlpath );
El. setattribute ("itemtitle", title );
Rootnode. prependchild (EL); // Add the newly added image news to the first position.
If (xnl. Count> 5)
{
Xmlnode lxn = rootnode. lastchild;
Rootnode. removechild (lxn); // deletes the final picture news.
}
Xmldoc. Save (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
//}
}
Function for modifying the attributes of an XML node:Copy codeThe Code is as follows: // <summary>
/// Modify XML attributes
/// </Summary>
/// <Param name = "picpath"> </param>
/// <Param name = "htmlpath"> </param>
/// <Param name = "title"> </param>
/// <Param name = "aid"> </param>
Public void editpicnewsxml (string picpath, string htmlpath, String title, string aid)
{
Xmldocument xmldoc;
Xmldoc = new xmldocument ();
Xmldoc. Load (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
Xmlnodelist xnl = xmldoc. selectsinglenode ("bcaster"). childnodes;
Foreach (xmlnode Xn in xnl)
{
Xmlelement Xe = (xmlelement) xn;
If (Xe. getattribute ("ID") = aid) // rewrite if a node exists
{
Xe. setattribute ("item_url", picpath );
Xe. setattribute ("Link", htmlpath );
Xe. setattribute ("itemtitle", title );
Break;
}
}
Xmldoc. Save (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
}
Function used to delete a specified XML node:Copy codeThe Code is as follows: // <summary>
/// Delete the specified XML Node
/// </Summary>
/// <Param name = "aid"> </param>
Public void delpicnewsxml (string aid)
{
Xmldocument xmldoc;
Xmldoc = new xmldocument ();
Xmldoc. Load (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
Xmlnodelist xnl = xmldoc. selectsinglenode ("bcaster"). childnodes;
Foreach (xmlnode Xn in xnl)
{
Xmlelement Xe = (xmlelement) xn;
If (Xe. getattribute ("ID") = aid) // delete a node if it exists
{
Xe. removeall ();
Break;
}
}
Xmldoc. Save (httpcontext. Current. server. mappath ("../picnews/bcastr. xml "));
}