<user Id="4/30/2015 10:16:52 AM">
<city>Bathinda</city>
<city>Moga</city>
<city>Patiala</city>
<city>Amritsar</city>
<city>Faridkot</city>
</user>
I want to make an entry in under user node having Id attribute value for this purpose I've used the code following:->
xmlDocument.Elements("user")
.Where(x => (string)x.Attribute("Id") == usrCookieId)
.FirstOrDefault()
.AddAfterSelf(
new XElement("adults", drpAdult1.SelectedIndex),
new XElement("kids", Convert.ToInt32(drpKids.SelectedIndex)),
new XElement("infants", Convert.ToInt32(drpInfants.SelectedIndex)),
new XElement("startingDate", datePicker.Value),
new XElement("startingCity", drpStartingCity.SelectedValue ));
But the Error is Object refrence is not set to an instance of an object. How can i correct my code above. Thanks!