Deleting xml node trough datagrid

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<br/>
Hello,<br/>
<br/>
I have a datagrid buttoncolumn which acts as the delete buttons for my xml nodes.<br/>
The elements names in the xml are simply displayed in a boundcolumn.<br/>
<br/>
Each item generated gets a unique id (each time one is made id++).<br/>
My question his how can i remove a item (the entire element node with that certain id) when i click on one of the delete buttons in the buttoncolumn?<br/>
<br/>
<div style="color:Black; background-color:White
<pre><span style="color:Blue <<span style="color:#A31515 root<span style="color:Blue > <br/><span style="color:Blue <<span style="color:#A31515 element <span style="color:Red id<span style="color:Blue =<span style="color:Black "<span style="color:Blue 0<span style="color:Black "<span style="color:Blue > <br/><span style="color:Blue <<span style="color:#A31515 name<span style="color:Blue >One<span style="color:Blue </<span style="color:#A31515 name<span style="color:Blue > <br/> <span style="color:Blue </<span style="color:#A31515 element<span style="color:Blue > <span style="color:Blue <br/> <<span style="color:#A31515 element <span style="color:Red id<span style="color:Blue =<span style="color:Black "<span style="color:Blue 1<span style="color:Black "<span style="color:Blue > <span style="color:Blue <br/> <<span style="color:#A31515 name<span style="color:Blue >Two<span style="color:Blue </<span style="color:#A31515 name<span style="color:Blue > <br/> <span style="color:Blue </<span style="color:#A31515 element<span style="color:Blue > <span style="color:Blue <br/></<span style="color:#A31515 root<span style="color:Blue >
[/code]


<div style="color:Black; background-color:White
<pre><span style="color:Blue protected <span style="color:Blue void dg_DeleteCommand(<span style="color:Blue object sender, DataGridCommandEventArgs e) <br/>{<br/> XmlFunctions.Remove(index); <br/>}<span style="color:Green /*dg_DeleteCommand*/<br/><br/><br/>//(function <span style="color:Blue on other <span style="color:Blue class, <span style="color:Blue where all my xml methods are written) <br/><span style="color:Blue <br/>public <span style="color:Blue static <span style="color:Blue void Remove() <br/>{ <br/> XmlDocument XMLDoc = <span style="color:Blue new XmlDocument(); <br/>XMLDoc.Load(XMLFile); <br/>XPathNavigator nav = XMLDoc.CreateNavigator(); <br/><span style="color:Blue var node = nav.SelectSingleNode(<span style="color:#A31515 "/root/element[@id=" +???+ <span style="color:#A31515 "]"); <br/>node.DeleteSelf(); <br/>XMLDoc.Save(XMLFile); <br/>}
[/code]

Best regards.




<br/>
<br/>

View the full article
 
Back
Top