target an XML Node to change value
I have an XML file as follows :-
<Root>
<Player>
<name>Name</name>
<surname>Surname</surname>
<rating>10</rating>
</Player>
<Player>
<name>Name1</name>
<surname>Surname1</surname>
<rating>20</rating>
</Player>
</Root>
Now I wish to target one of these nodes so that I can do some changes to it.
I have the following code :-
XElement playerXML =
doc.Root.Elements("Player").FirstOrDefault(x =>
x.Element("name").ToString() == playerInput.name
&&
x.Element("surname").ToString()
==
playerInput.surname
&&
Convert.ToInt32(x.Element("rating"))
==
playerInput.rating);
if (playerXML != null)
{
//do processing
}
However I am not getting anything back, even though the name, surname and
rating are in the file.
What am I doing wrong?
Thanks for your help
No comments:
Post a Comment