C
C
CodeInside2018-04-03 10:59:47
.NET
CodeInside, 2018-04-03 10:59:47

Why is linq query not finding data in xml file?

XML file with data

<?xml version="1.0" encoding="utf-8"?>
<Users>
  <User>
    <Login>login</Login>
    <PasswordMD5>5f4dcc3b5aa765d61d8327deb882cf99</PasswordMD5>
  </User>
</Users>

How do I get the data
XDocument doc = XDocument.Load(PATH_TO_DATA_FILE);
var user = from User in doc.Root.Elements("Users")
                 where User.Element("Login").Value == login
                 select User;

But in the end, when the value of the login variable matches the value in the file - user.Count = 0. That is, the linq query does not find nodes with this value. What could be the problem and how to correctly build a Linq query, because it doesn’t work on my own?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-04-03
@freeExec

Root is already the Users level. You need to take the User element

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question