I need to know about to read xml file from project directory as shown below code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using crudpartialviewsjqueryajax.Models;
using System.Data;
using System.Xml;
namespace crudpartialviewsjqueryajax.Controllers
{
public class snehprajapatController : Controller
{
public void getinstructors()
{
try
{
List<string> name = null;
XmlDocument xml = new XmlDocument();
xml.LoadXml(@"~\App_Data\Trainings.xml");//Here given xml path location
XmlNodeList xnList = xml.SelectNodes("/Trainings/Training");
foreach (XmlNode xn in xnList)
{
new List<string>{ xn["name"].InnerText };
}
//return name;
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
}
}
I'm getting this error:
An unhandled exception of type 'System.Xml.XmlException' occurred in System.Xml.dll
Additional information: Data at the root level is invalid. Line 1, position 1.
Please see the above code and suggest what to do to fix this?
Thanks in advance