// This is needed when accessing an XElement or Attribute that has a namespace on its name
XNamespace xts = "http://www.xmlteam.com";
List<Object> mySchedules = new List<object>();
XElement Root = xmlDoc.Root;
List<DocumentSportsInfo> docSportsInfo =
(from listing in xmlDoc.Descendants("sports-content")
let SportsMetadata = listing.Elements("sports-metadata").First()
let SportsContextCode = listing.Descendants("sports-content-code")
select new DocumentSportsInfo
{
//QueryDateTime = myFodHelper.ConvertFodDateTime(Root.Attribute("query-date-time").Value),
QueryString = Root.Attribute("query-string").Value,
HostName = Root.Attribute("hostname").Value,
ResultCount = Convert.ToInt32(Root.Attribute("result-count").Value),
ErrorCount = Convert.ToInt32(Root.Attribute("error-count").Value),
TotalCount = Convert.ToInt32(Root.Attribute("total-count").Value),
ElapsedTime = Root.Attribute("elapsed-time").Value,
DocumentId = SportsMetadata.Attribute("doc-id").Value,
//DocumentDateTime = myFodHelper.ConvertFodDateTime(SportsMetadata.Attribute("date-time").Value),
DocumentClass = SportsMetadata.Attribute("document-class").Value,
FixtureKey = SportsMetadata.Attribute("fixture-key").Value,
RevisionId = SportsMetadata.Attribute("revision-id").Value,
DocumentSportsTitle = SportsMetadata.Element("sports-title").Value,
Priority = SportsContextCode
.Where(c => c.Attribute("code-type").Value == "priority")
.Select(c => c.Attribute("code-key").Value).FirstOrDefault(),
Sport = SportsContextCode
.Where(c => c.Attribute("code-type").Value == "sport")
.Select(c => c.Attribute("code-key").Value).FirstOrDefault(),
League = SportsContextCode
.Where(c => c.Attribute("code-type").Value == "league")
.Select(c => c.Attribute("code-key").Value).FirstOrDefault(),
Conference = SportsContextCode
.Where(c => c.Attribute("code-type").Value == "conferenece")
.Select(c => c.Attribute("code-key").Value).FirstOrDefault(),
TeamKeys = SportsContextCode
.Where(c => c.Attribute("code-type").Value == "team")
.Select(c => c.Attribute("code-key").Value).ToList(),
}).ToList();
mySchedules.Add(docSportsInfo);
Console.WriteLine("Hello");
List<object> eventAndTeamInfo =
(from sEvent in Root.Descendants("sports-event")
select new List<object>
{
new EventSportsInfo
{
Key = sEvent.Element("event-metadata").Attribute("event-key").Value, //event-status
Status = sEvent.Element("event-metadata").Attribute("event-status").Value,
Week = Int32.Parse(sEvent.Element("event-metadata").Element("event-metadata-american-football").Attribute(xts + "week").Value),
// Add the others here
},
new List<TeamsSportsInfo>
(
(from t in sEvent.Descendants("team")
// The let's are here so that you do not have to write them 4 times and can
// be used short string and can combine them as in FullName
let FN = t.Element("team-metadata").Element("name").Attribute("first").Value
let LN = t.Element("team-metadata").Element("name").Attribute("last").Value
select new TeamsSportsInfo
{
// Add fileds here
Key = t.Element("team-metadata").Attribute("team-key").Value,
FirstName = FN,
LastName = LN,
FullName = FN + " " + LN
// Add more fileds here
}).ToList()
),
} as object
).ToList();
mySchedules.Add(eventAndTeamInfo);
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.