I have an XML File:
<?xml version="1.0" encoding="utf-8"?>
<Options>
<Gestion>
<Prêts>
<NbrRenouvlement>5</NbrRenouvlement>
<DureeEmprunt>10</DureeEmprunt>
<NbrEmprunt>3</NbrEmprunt>
</Prêts>
<Réservations>
<NbrReservation>3</NbrReservation>
<DureeReservation>7</DureeReservation>
</Réservations>
</Gestion>
<Config>
<RememberMe>False</RememberMe>
<ConnexionAutomatique>False</ConnexionAutomatique>
<ShowToolTip>True</ShowToolTip>
</Config>
</Options>
I want to select the value of NbrRenouvlement which is 5, and this is the code I wrote:
String nbrReservation = String.Empty;
var makeInfo = from reservations in doc.Descendants("Réservations")
select reservations.Element("NbrReservation").Value;
but this code is returns a Generic List, inspite of the value I want to select is just one number so I need to work with a foreach loop:
foreach (string s in makeInfo.Distinct())
nbrReservation.Text += s;
This methods works fine but it's too long for select one value, is there any other method that allows me to select the value of NbrReservation from that XML file?
And how can I change this value ?
NbrRenouvlementbut your code tries to get the value ofRéservations/NbrReservation. Can you clarify what you really want to do?NbrRenouvlement) and your code is doing contradicts(you are selectingRéservations/NbrReservation).