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:
/// <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 ")); } |