Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get multiple values from XML file.
I use below code.
C#
var q = (from c in xDoc.Descendants("Login") where c.Element("UserName").Value == txtuname.Text.ToString() select (string)c.Element("UserName"));

But using above code,i get only one node value.
Posted
Updated 16-Oct-13 3:02am
v2
Comments
Gabriel Szabo 16-Oct-13 11:32am    
Your code is returning only one node because you are filtering "Login" elements by their "UserName" child element's value. You only get the "UserName" element whose value is equal to txtuname.Text.

For examplpe, if you remove the where clause, you will get "UserName" child elements for all your "Login" elements.

What exactly is your intent?

1 solution

If you want multiple "UserName"s, can you verify that there are more than one branch with the username you are searching for? It looks like it is looking to match exactly one login value...

If you want to select multiple values for each result, you need to create new output results... try something like:

var q = (
from c in xDoc.Descendants("Login")
where c.Element("UserName").Value == txtuname.Text.ToString()
select new { (string)c.Element("UserName"), (string)c.Element("OtherValue")) };
 
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