I'm trying to get the value of supplierCacheTolerance, how can I do that, I have the following code, but it throws a Object reference not set to an instance of an object
public IEnumerable<CachedSupplierResponse> CachedResponse()
{
XNamespace ns2 = "url/";
var doc = XDocument.Parse(DownloadEanXmlFile.GetEanXmlFile());
var cacheTolerance = (doc.Descendants(ns2 + "HotelListResponse").Select(c => new CachedSupplierResponse()
{
SupplierCacheTolerance = c.Element("cachedSupplierResponse").Attribute("SupplierCacheTolerance").Value
}));
return cacheTolerance.AsEnumerable();
}
Any help would be appreciated.
Thanks
Fixed problem, typo on my behalf, SupplierCacheTolerance should have been supplierCacheTolerance
Member
9 Points
70 Posts
help with getting value from xml file and display in controller
Apr 20, 2013 06:11 AM|George Phillipson|LINK
Hi
I'm new to xml and mvc and i'm stuck on the following problem.
I have the following snippet of xml
I'm trying to get the value of supplierCacheTolerance, how can I do that, I have the following code, but it throws a Object reference not set to an instance of an object
Any help would be appreciated.
Thanks
Fixed problem, typo on my behalf, SupplierCacheTolerance should have been supplierCacheTolerance
All-Star
24482 Points
1804 Posts
Re: help with getting value from xml file and display in controller
Apr 22, 2013 03:48 AM|Young Yang - MSFT|LINK
The doc’s type is XDocument,not the root node.You can use Root to get the root element.
SupplierCacheTolerance = c.Root.Element("cachedSupplierResponse").Attribute("SupplierCacheTolerance").Value
Feedback to us