Click here to Skip to main content
16,017,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to convert foreach loop into LINQ?
C#
foreach (XmlNode item in xmlnode)
               {
                   if (strArr.Contains(item.Attributes.GetNamedItem(MspecAttribute).Value))//search the XML with the values in the array
                   {
                       //add the XML values to the datatable
                       dt.Rows.Add(item.Attributes.GetNamedItem(MspecAttribute).Value, item.Attributes.GetNamedItem(XmlNameAttribute).Value);
                   }
               }


I have a string array with the values i am searching a XML file and fetching the values.
Posted
Comments
PIEBALDconsult 7-Jul-15 1:33am    
Why?
And have you tried XPath?

1 solution

Hi

Try below code:

C#
XElement x = XElement.Load(@"Items.xml");
                string strCompare = "Test";
                                var element = from XMLelement in x.Elements("Item")
                              where (string) XMLelement.Attribute("Value")==strCompare
                              select XMLelement;



Thanks
Harshad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900