<? XML version = "1.0" encoding = "gb2312"?>
<Root>
<Comment>
<URL> http://image.meimumeijia.com/product_comment/2013/08/327956_201308161103132272_small.jpg </URL>
<DESC> test the function! </DESC>
</Comment>
<Comment>
<URL> http://image.meimumeijia.com/product_comment/2013/08/327956_201sdfsdf272_small.jpg </URL>
<DESC> test and test sdfs! </DESC>
</Comment>
</Root>
/// <Summary>
/// Create and add an XML Node
/// </Summary>
/// <Param name = "url"> image link </param>
/// <Param name = "DESC"> description </param>
Public void createxmlnode (string URL, string DESC)
{
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (system. Web. httpcontext. Current. server. mappath ("/") + "Product/comment. xml ");
Xmlnode root = xmldoc. selectsinglenode ("root ");
Xmlelement xe1 = xmldoc. createelement ("comment ");
Xmlelement xesub1 = xmldoc. createelement ("url ");
Xesub1.innertext = URL;
Xe1.appendchild (xesub1 );
Xmlelement xesub2 = xmldoc. createelement ("DESC ");
Xesub2.innertext = DESC;
Xe1.appendchild (xesub2 );
Root. appendchild (xe1 );
Xmldoc. Save (system. Web. httpcontext. Current. server. mappath ("/") + "Product/comment. xml ");
}
/// <Summary>
/// Delete the first subnode of the XML file
/// </Summary>
Public void deletexmlnode ()
{
Xmldocument xmldoc = new xmldocument ();
Xmldoc. Load (system. Web. httpcontext. Current. server. mappath ("/") + "Product/comment. xml ");
Xmlnodelist xnl = xmldoc. selectsinglenode ("root"). childnodes;
If (xnl. Count <5)
{
Return;
}
Foreach (xmlnode Xn in xnl)
{
If (xnl. Item (0) = xn)
{
XN. parentnode. removechild (Xn); // delete a node (including the secondary Node itself)
Break;
}
}
Xmldoc. Save (system. Web. httpcontext. Current. server. mappath ("/") + "Product/comment. xml ");
}