7
Answers

Xml data

Rick Freeman

Rick Freeman

9y
550
1
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 were using xdoc.Descendants("game") I should be able to query the doc even if these elements are included, however I get a null...
 
The class also includes a "root" reference:
[Serializable]
[XmlRoot("game"), XmlType("game")]
public class Games
{
 
 When I remove the two elements the query works!
Answers (7)
1
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
Is that resolve your problem? If it really helped please accept the answer. 
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
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
Rick Freeman

Rick Freeman

NA 30 4.7k 9y
Please see attached...
0
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
As I told earlier please whole xml content otherwise it difficult to write LINQ to XML.
0
Rick Freeman

Rick Freeman

NA 30 4.7k 9y
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
Rick Freeman

Rick Freeman

NA 30 4.7k 9y
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
Manas Mohapatra

Manas Mohapatra

NA 29.3k 3.3m 9y
Please provide total content xml data and what are you trying to query...
Next Recommended Forum