Error in loading xml file

Posted by Klbaiju under WCF on 2/6/2013 | Points: 10 | Views : 1183 | Status : [Member] | Replies : 3
Hi,
In my wcf application, i want to load xml file
i use this code but showing error.
error is object reference not set instance of an object

public class Service : IService
{
public IEnumerable<person> disp(string city)
{

XDocument xmlDoc = XDocument.Load(HttpContext.Current.Server.MapPath("people.xml"));
IEnumerable<person> persons = from p in xmlDoc.Descendants("person")
where p.Element("City").Value == city
select new person
{
Name = p.Element("Name").Value,
City = p.Element("City").Value,
Age = p.Element("Age").Value,

};
return persons.ToList();
}

}

how to solve this.

Regards
Baiju




Responses

Posted by: Sakthi.Singaravel on: 2/7/2013 [Member] Silver | Points: 25

Up
0
Down
Re-Write the XDocument as follows:

XDocument xmlDoc = new XDocument();

xmlDoc =XDocument.Load(HttpContext.Current.Server.MapPath("people.xml"));


Regards,
Singaravel M

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sakthi.Singaravel on: 2/10/2013 [Member] Silver | Points: 25

Up
0
Down
are you got solution...?

Regards,
Singaravel M

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 2/11/2013 [Member] Starter | Points: 25

Up
0
Down
Hi..
You can refer the below link to load xml and search using LINQ
http://www.dotnetcode.in/2013/02/how-to-use-linq-query-in-xml-data-souce.html

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response