Xml/Xslt - How to delete element in xml using C#

Asked By Sam Sam on 28-Mar-11 08:40 AM
This is my XML File: 
<?xml version="1.0" encoding="UTF-8"?>
<flash_parameters copyright="anvsoftPFMTheme">
  <preferences>
    <global>
      <basic_property movieWidth="480" movieHeight="400" html_title="Title" loadStyle="Bar" startAutoPlay="true" continuum="true" backgroundColor="0x000000" hideAdobeMenu="false" anvsoftMenu="false" photoDynamicShow="true" enableURL="true" transitionArray="" defineTransitionEffects="38,42" clickToAutoPlay="false" frameRate="30" />
      <title_property showTitle="true" photoTitleColor="0xffffff" backgroundColor="0x000000" alpha="30" autoHide="true" />
      <music_property path="" stream="true" loop="true" enableVolumeDrag="true" defaultVolume="80" musicButtonColor="0xffffff" />
      <photo_property topPadding="0" bottomPadding="40" leftPadding="0" rightPadding="0" />
      <properties enable="true" backgroundColor="0x000000" backgroundAlpha="30" cssText="a:link{text-decoration: underline;} a:hover{color:#ff0000; text-decoration: none;} a:active{color:#0000ff;text-decoration: none;} .blue {color:#0000ff; font-size:15px; font-style:italic; text-decoration: underline;} .body{color:#ff5500;font-size:20px;}" align="bottom" />
    </global>
    <thumbnail>
      <basic_property thumWidth="35" thumHeight="30" borderColor="0x808080" currentBorderColor="0xffffff" thumborder="1" thumSpacing="5" buttonColor="0xffffff" />
    </thumbnail>
  </preferences>
  <album>
    <slide jpegURL="thumbs/t_0001.jpg" d_URL="slides/p_0001.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="1zp7cya" width="480" height="360" />
    <slide jpegURL="thumbs/t_0002.jpg" d_URL="slides/p_0002.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="article-1339166-0C8236B4000005DC-99_964x656" width="480" height="360" />
    <slide jpegURL="thumbs/t_0003.jpg" d_URL="slides/p_0003.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="beautiful_bird_1024x768" width="480" height="360" />
    <slide jpegURL="thumbs/t_0001.jpg" d_URL="slides/p_0001.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="1zp7cya" width="480" height="360" />
    <slide jpegURL="thumbs/t_0004.jpg" d_URL="slides/p_0004.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="1zp7cya" width="480" height="360" />
    <slide jpegURL="thumbs/t_0005.jpg" d_URL="slides/p_0005.jpg" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="1zp7cya" width="480" height="360" />
    <slide jpegURL="thumbs/t_p_00019.jpg" d_URL="slides/p_00019.JPG" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="p_00019.JPG" width="480" height="360" />
    <slide jpegURL="thumbs/t_p_00040.jpg" d_URL="slides/p_00040.JPG" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="p_00040.JPG" width="480" height="360" />
  </album>
</flash_parameters>


 I want to delete this element:

 <slide jpegURL="thumbs/t_p_00040.jpg" d_URL="slides/p_00040.JPG" transition="0" panzoom="1" URLTarget="0" phototime="2" transitiontime="2" url="http://www.ultraslideshow.com" title="p_00040.JPG" width="480" height="360" />


So, how can i delete this element by jpegURL id.
Help Me.


kiran k replied to Sam Sam on 28-Mar-11 08:51 AM
you can delete the xml node using XPathNavigator.
 
 refer this article it will helps you .http://msdn.microsoft.com/en-us/library/xws54wwx.aspx
Reena Jain replied to Sam Sam on 28-Mar-11 08:53 AM
hi,

here is the code for you

private void button1_Click(object sender, EventArgs e)
     {
       String path = Environment.CurrentDirectory + @"\Doctors.xml";
       XmlDocument d = new XmlDocument();
 
       d.Load(path);
 
       XmlNode t = d.SelectSingleNode("nodename");
 
       t.ParentNode.RemoveChild(t);
 
       d.Save(path);
 
     }

hope this will help you