.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 criteria - linq to xml

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

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?




View Complete Post

More Related Resource Links

delete node based on child value

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!

Is there a way to query entity based on multiple filter criteria? WCF Data Services, Linq to Entiti


Instead of:

DW_CMSOPEN dwc = new DW_CMSOPEN(new Uri("http://acctdev02/WCFDataService/EmployeeService.svc"));

dwc.Credentials = System.Net.CredentialCache.DefaultCredentials;

var employees = from emp in dwc.Employees 
             where emp.DEPT == "123"
             select emp;

I'd like the linq query to resemble:

var employees = from emp in dwc.Employees
              where emp.DEPT // in {"123", "456", etc}
              select emp;

VSTO: Build Office-Based Solutions Using WPF, WCF, And LINQ


With Visual Studio Tools for Office you can easily build Office-based services that harness the power of Windows Communication Foundation, Windows Presentation Foundation, and LINQ.

Andrew Whitechapel

MSDN Magazine December 2007

dropdownbox which selects records based on criteria (TODAY, THIS WEEK, THIS MONTH, etc)


I have a dropdownbox which I want to use to search records based on a timescale. The gridview populates results based from that search.

So here is how I want to work this;

If a user selects "today" - a list of records input today are populated. If "this week" is selected, a list of all records added within that week from todays date is populated.

I created a forum on this issue previously but to no avail whatsoever. How do I work around this problem?

Help would be much appreciated

LinQ to check if xml node exists in the XML??

Using LinQ or any C# syntax, I just want to know whether "Item" Child exists or not if the parent Node (ChildMenuSelected>>MenuSelected) are true from the below xml format.Xml Format:<MenuDataResult> <Items> <Item> <ItemType>Submenu</ItemType> <ItemTitle>Level22</ItemTitle> <Menu> <MenuSelected>false</MenuSelected> <ChildMenuSelected>false</ChildMenuSelected> </Menu> </Item> <Item> <ItemType>Submenu</ItemType> <ItemTitle>Level21</ItemTitle> <Menu> <MenuSelected>false</MenuSelected> <!--if ChildMenuSelected = true --> <ChildMenuSelected>true</ChildMenuSelected> <Item> <ItemType>Submenu</ItemType> <ItemSubType>0</ItemSubType> <Menu> <!--if MenuSelected = true --> <MenuSelected>true</MenuSelected> <ChildMenuSelected>false</ChildMenuSelected> <!-- whether this below item exists or not --> <Item> <ItemType>Submenu</ItemType> <Menu> <MenuSelected>false</MenuSelected> <ChildMenuSelected

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

delete a row in datatable using linq to dataset

hihow can i delete a row in datatable using linq to dataset?I have a dataset in my project, need to delete some rows filtered by IDhow can i do?

LINQ - Can't perform Create, Update or Delete operations on because it has no primary key.

Hi, not sure if I'm posting this thread in the right section. anyway, I''m trying to do the update/insert/delete using LINQ but the underlying table does not a primary key. The table consists of composite ket (e.g. fieldA & FieldB make a primary key). At the moment, I have LINQ complaning about not having a single primary key (not sure what LINQ does it - not making any sense at all). did anyone ever come across this issue and rectified it?  thanks

Is the delete records LINQ correct ?

I hope to delete all records in DBPrograms, is the following code correct?               DBContext db = DBContext(PublicDBPar.ConnectionString);            db.DBPrograms.DeleteAllOnSubmit(db.DBPrograms);            db.SubmitChanges();

linq - delete dropdownlist

My code:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"DataSourceID="LinqDataSource1" DataTextField="UserId" DataValueField="UserId"></asp:DropDownList>BurnbetDataDataContext db = new BurnbetDataDataContext();        var selectedID = (DropDownList1.SelectedValue);        tbl_Payment toDelete = db.tbl_Payments.Single(p => p.UserId == selectedID);        db.tbl_Payments.DeleteOnSubmit(toDelete);        db.SubmitChanges();Error:System.InvalidOperationException was unhandled by user code  Message=Sequence contains more than one element  Source=System.Data.Linq  StackTrace:       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IPr

linq - delete two tables not work

BurnbetDataContext db = new BurnbetDataContext(); var q = (from c in db.GetTable<tbl_Payment>() where c.UserId == "fc44c835-8e80-45ee-af84-68339a09c053" select c).Single<tbl_Payment>(); db.GetTable<tbl_Payment>().DeleteOnSubmit(q); db.SubmitChanges(); In App_Code I BurnbetDataContext.I have two tables and tbl_PaymentDetails tbl_PaymentAssociation is:Parent Child Class -->>> UserId UserId ClassData in Table tbl_PaymentDetails (child) does not delete.      

MS Linq To SQL Samples - Insert/Update/Delete

Hi, I'm stumbling along trying my hand at Linq to SQL and have come across this code below that was provided by MS.http://msdn.microsoft.com/en-us/vbasic/bb737928.aspxThe problem is there is no ".add" method for Categories to chose in the statement db2.Categories.add(newCategory)I've seen similar videos here on ASP .NET that uses code very much like the example below, but I am unable to run this example connected to a Northwind SQL database using Web Developer 2010 Express. This is the One-to-Many example listed under Linq To SQL Samples - Insert/Update/Delete. Thanks for any help! Shawn Dim db2 = New DataClassesDataContext Dim ds = New DataLoadOptions() ds.LoadWith(Of Category)(Function(p) p.Products) db2.LoadOptions = ds Dim newCategory = New Category With {.CategoryName = "Widgets", _ .Description = "Widgets are the customer-facing analogues " & _ "to sprockets and cogs.", _ .Picture = Nothing} Dim newProduct = New Product With {.ProductName = "Blue Widget", _ .UnitPrice = 34.56#, _ .Category = newCategory, _

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

populate dropdown based on attribute criteria

Trying to load a dropdown list with the 'name' attribute from the category node...must be missing something: The xml: <Settings>  <department name="Accounting">    <category name="Bank Information">    <category name="Form Information"></Settings>    The code I'm attempting: XmlDocument settingsdoc = new XmlDocument();                settingsdoc.Load(Server.MapPath("/XML/Settings.xml"));                XmlNodeList nodeList = doc.SelectNodes("Settings/department[name='Accounting']");                 foreach (XmlNode node in nodeList)                    CategoryDDL.Items.Add(new ListItem(node.SelectSingleNode("//department/category[name]").InnerText)); CategoryDDL.DataBind();   Any idea what looks wrong? Thanks!

How to update and delete with Linq?



I use Linq to Entities and want to update and delete data. I know the ID of the object / record.

How can  update and delete without first selecting the complete object (asuming that this is better for performance)?


SharePoint 2010 Approval workflow based on list criteria


Hello All

I have been requested to create an Approval workflow for a list with 3 columns - Title, Category and Price. The Category field has 3 options - Minor, Moderate and Major.

If the Category is Minor the approval is sent to the Project Manager, and after approval it is sent to the Manager for approval.

How can I accomplish this using SharePoint Designer 2010? Can I modify the OOTB approval workflow, if yes how?

What other options do I have? This is really urgent.

Thank you for any responses.




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