1
Is that resolve your problem? If it really helped please accept the answer.
0
XDocument xdoc = XDocument.Load(Server.MapPath("Daily_schedule.xml"));
XNamespace ns = "http://feed.elasticstats.com/schema/basketball/schedule-v2.0.xsd";
var gameList = (from rec in xdoc.Descendants(ns + "game")
where (string)rec.Attribute("id") == "53a41428-d8f7-4020-97cc-13792e6994eb"
select new
{
id = rec.Attribute("id").Value,
venue = rec.Element(ns + "venue").Attribute("name").Value,
home = rec.Element(ns + "home").Attribute("name").Value,
away = rec.Element(ns + "away").Attribute("name").Value,
status = rec.Attribute("status").Value,
scheduled = rec.Attribute("scheduled").Value
}).ToList();
foreach (var p in gameList)
{
// Append your other properties
Response.Write(p.id + p.status);
}
Note: You are getting because XML namespace is present in XML data. So LINQ to XML is looking namespace name in each element name.
0
Please see attached...
0
As I told earlier please whole xml content otherwise it difficult to write LINQ to XML.
0
My xml doc is returned with these two elements that are effecting the query:
<league xmlns="http://feed.elasticstats.com/schema/basketball/schedule-v2.0.xsd" id="4353138d-4c22-4396-95d8-5f587d2df25c" name="NBA" alias="NBA">
<season-schedule id="5ddc217a-a958-4616-9bdf-e081022c440b" year="2013" type="REG">
<games>
<game > ect...
Since we're using xdoc.Descendants("game") I should be able to query the xml even if these elements are included, however I get a null...
I'm using this query:
var tempList = (from r in document.Descendants("game").Where
(r => (string)r.Attribute("id") == "53a41428-d8f7-4020-97cc-13792e6994eb")
select new
{
id = r.Attribute("id").Value,
venue = r.Element("venue").Attribute("name").Value,
home = r.Element("home").Attribute("name").Value,
away = r.Element("away").Attribute("name").Value,
status = r.Attribute("status").Value,
scheduled = r.Attribute("scheduled").Value
}).ToList();
public class Games
{
public List<Games> games { get; set; }
public string id { get; set; }
public string home { get; set; }
public string away { get; set; }
public string venue { get; set; }
public string status { get; set; }
public string scheduled { get; set; }
}

0
I will be using the same method provided. I'm looking for a method to use the xml file without having to remove the and elements that are causing the query to return null...
0
Please provide total content xml data and what are you trying to query...