.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

delete node based on child value

Posted By:      Posted Date: September 18, 2010    Points: 0   Category :ASP.Net
Trying to delete a node via linq to xml but don't seem to be creating my query just right. My xml looks like this: <Index><Document>    <FriendlyName>test</FriendlyName>    <ID>f1eb6439-56dc-4f8a-a02a-c97706646643</ID>    <Post>True</Post>    <Department>Clearance</Department>    <Category>Information</Category>    <Audience></Audience>    <Link Type="Page" Target=""><![CDATA[]]></Link>    <Keywords></Keywords>  </Document></Index>   I know the ID that i want and is stored in variable myID Now I need to search my xml & find the entry that matches myID Then delete the entire Document element & all child nodes.   Here's what I've been playing with but it's just not quite there. myxmldoc.Elements("Document").Where(s => s.Element("ID").Value == myID).Remove();    Thanks ahead for the help!

View Complete Post

More Related Resource Links

delete node based on criteria - linq to xml


I'm trying to delete an element based on its inner text but seem to not quite have it...

I have an xml doc like this:
<department name="Claims">
    <MyElement>Big Test</MyElement>


My linq to xml is:

XDocument ldoc = XDocument.Load(Server.MapPath("/XML/Settings.xml"));

doc.Elements("department").Where(s => s.Element("keywords").Value == "phone").Remove();



When I click my link button the element <keywords>phone</keywords> is never deleted.

Any idea what i'm doing wrong?




Display homepage node along with child nodes


If the first Sitemap node is your homepage/default and all other nodes are supposed to be children / grandchildren of the first sitemap node in a web.sitemap, how do I set up my web.sitemap to enable me to display my cssFriendlyMenu with the homepage node along with the nodes that are 1 level down from it at the same time as in :

Home   Products   Services   About us


...or is it not possible to have the first sitemap node displayed along with the nodes that are 1 level down from it?  Do I need to have a different starting node rather than my homepage node?

How can i update treeview root node every time based on the record entries

Hi all, I will have an mdi form and with a treeview which has it's initial property as visible =false. If i select an option from menu a child form will exists i will fill some details and click on save when ever click on save i will make the root node of the treeview to some name as File[batch count:0]. Now if i select another option from menu another form will appear and if i fill it with some details and click on save i would like to change the root node name to File[batch count:1] and a child node should exists with some name

Receive/Delete Multiple FTP Files based on condition using SCRIPT(VB) TASK

I am trying to receive and delete multiple FTP files from a remote FTP server using Script task Below is the code   Dim FTPConnMgr As ConnectionManager FTPConnMgr = Dts.Connections("FTP Connection Manager") Dim FTPClientConn As FtpClientConnection = New FtpClientConnection(FTPConnMgr.AcquireConnection(Nothing)) Dim FileTimeStampNew As String = "20100913021807" Dim remoteFileNames(0) As String remoteFileNames(0) = Dts.Variables("FtpRemoteDirectory").Value & "*" & FileTimeStampNew & ".*" 'Below hardcoded FileName works good. But the problem is there are lots of file in the FTP folder that I dont want to receive 'remoteFileNames(0) = Dts.Variables("FtpRemoteDirectory").Value & "Company_alpha_Full_20100913021807.xml" Dim localPath As String = Dts.Variables("FtpLocalDirectory").Value FTPClientConn.Connect() FTPClientConn.ReceiveFiles(remoteFileNames, localPath, False, False) FTPClientConn.Close() Dts.TaskResult = ScriptResults.Success End Sub End Class If i specifically mention the RemotefileNames this works fine but, when I say *.* it executes succefully but doesn't receives the file. Please advice how to receive multiple file based on a variable BR, AWM

Display error if a treeview root node contains a child node

I am having a treeview initially with a root node when form is loaded. I will add child node as some.txt file at the runtime by selecting an option as Addnew from contextmenu which was displayed when the user right clicks on the root node. Now what i need is if the tree has child node appended to the Root and if user tries to create a new node by clicking the option addnew from context menu i would like to display an error as only one child allowed.   Can any one help

How to display TreeViewItems different ways based on the item type under a single node?

Hi, I am having trouble trying to display hiearchical data under each node in two different ways depending on the data.  I hope someone will be able to provide me some help on this since I am rather new to WPF development. Maybe I am going about this all wrong but for now, I am trying to create a customized TreeView to represent data similar to the xml I provided in the code below.  The <ItemsPresenter/> instances listed in the code are not exactly doing what I need.  I will probably need to filter the content that I list with each of the two <ItemsPresenter/> tags based on the type of each item although I have no idea if this is possible.   <Window x:Class="Wpf_treeview_testing.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Window1" Height="300" Width="300"> <!-- * The "xmlData" describe roughly the type of data that I require visual representaion of. * Since I could not find a WPF Control that will present a Hierachical Data Template close to what we need, I am trying to setup a TreeView to represent this information by using a ControlTemplate for TreeViewItem. * The preferred result is to present different items types in

Disable child links in list.aspx : gridView based on some row condations


In the list.aspx page , Datagridview


I want to disable the links to the child table based on condition ,

let say if filed OrderDate is empty at row in table Orders I want to disable link to OrderDetailes for that specific row

Add to xml node as a first child


Hi Folks,

I am new with ASP.NET, trying to build an application with the help of googling, now in XML section when I am updating my XML dynamically, by default the node would be added after the last node, I want to add it as a first child (as first child of <total> so that I can save sorting portion at data grid. Please have a look on the code and suggest me.




protected void BtnSubmit_Click(object sender, EventArgs e)


            string xx="", yy="", zz="",
            datacable = "",
            charger = "",
            issued_by= "";
            LblSummary.Text = "";
            Lblmsg.Text = "";

Displaying + on treeview node even when no child nodes are present


I have a treeview control that is working great, except that I would like the behavior of some nodes to display the + even though no child nodes exist yet. Meaning, I want my treeview control to look like this:

- RootNode
    + Node1
    + Node2
    + Node3

However, Nodes 1, 2, and 3 do not have any child nodes. From what I can see the + or - does not display if there are no child nodes, but I would like to see the + appear even though there are no child nodes. I want to do this because I want to create the child nodes upon expanding the parent node (Node1 for example).

Is this possible?



How to get nodes based on some values, update other element or delete that whole object



This is my xml string.

<xml version="1.0" encoding="utf-16">
    <x> test value 1 </x>
    <y> test value 2</y>

        <x> test value 3</x>
        <y> test value 4</y>

                <x> test value 5</x>
                <y> test value 6 </y>

                <x> test value 7</x>
                <y> test value 8 </y>

                    <x> test value 9</x>
                    <y> test value 6</y>







I have a big xml same as above containing a deep hierarchy.

Now, I am looking to do two things.

1. I want to find a particular node/obj by checking <x> element value. so I want to get node ofwhich <x> value is "test value 3" and for that object, I want to update <y> value to "Some New Value".

2. I want to find all the nodes/objects by checking <y> element value is "test value 6" OR "test value 8" OR "test value

Delete row from datatable based on column value



I am populating a datatable with data from MSSQL and I have a need to then remove all rows in the datatable that have a certain value in a specific column.

Is there any way I can remove rows from a datatable by specifying the value in the column it should identify the rows by that should be removed? (eg like in MSSQL how you can say delete from tablename where field=value)?

The specified node cannot be inserted as the valid child of this node, because the specified node is


I am trying to display a portion of an xml file in a data grid.  I need to transform a number of elements to attribute to display in the grid. If i delete all of the additional elements in the xml file, my code works.  however i need those elements to remain in the XML file. So, here is what i got, maybe someone can help:

Working XML file (not useful):

<?xml version="1.0" encoding="utf-8"?>

Not working xml (need to have it work):

<?xml version="1.0" encoding="utf-8"?>

how to make a TreeNode in treeview as the 1st child node for every or specific Parent Treenode? w




How to  make a treenode  as the 1st child node for every parent node or for some specific parent nodes.

thanks in advance

about error in child node in menu



I created menu control and child nodes in .aspx page.i created childs also. where i created childs it is displayig "expand" instead of child name. the links has not working.but running it will run without error but displaying like the follwing.i didnt do any formatting simply created a menu.

Please help me to solve it.




Skip Navigation Links

Company Details
Process Owner's Details Expand Process Owner's Details

Problem to delete treeNode along with child nodes.



i have a treeView which display organization chart as hierarchical view. i want when end-user remove a treeNode, all childs of the selected node also being removed and then update database. to do this, i've used this code :

private void btnDeleteReceiver_Click(object sender, EventArgs e)

private void DeleteNode(TreeNode node)
      foreach (TreeNode childNode in node.Nodes)
      TestDataSet.ReceiversRow receiver = node.Tag as TestDataSet.ReceiversRow;

as u see in above code, i have a recursive method which delete all child nodes of the parentNode. but i'm facing a problem to delete all childs of the node. this loop could not iterate all childs node correctly. i don't know

WPF Selected xml node from treeview, I want to populate a datagrid with that node and all child node

I have populated a tree view from a xml.  I know want to take the node and all children that has been selected by double clicking on the tree node and populate a data grid.

Delete Child Record And Later Delete The Parent Record


need help in Sql script

how to Delete Child Record And Later Delete The Parent Record if it has no child

Trigger might be the answer but i don t know how!

if someone has another way tell me

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend