I am working on a project and am unsure about how I need to go about getting the data that I need from the XML file. This is the code that I have for getting the XML file and beginning to iterate through it.
public void Load(string xmlFile)
{
XDocument doc = XDocument.Load(xmlFile);
var query = from xElem in doc.Descendants("Jeopardy")
select new Answer
{
Category = Convert.ToString(xElem.Element("category").Value)
};
this.Clear();
AddRange(query);
}
Here is the first part of the XML file
<?xml version="1.0" encoding="utf-8"?>
<Jeopardy>
<category name = 'People in Computing'>
<first points = '100' answer = 'Alan Turing'>Known as the questioner of the human mind, this man is known for helping tell humans and computers apart.</first>
<second points = '200' answer = 'Grace Hopper'>This female pioneer of the COBOL computer programming language was an Admiral in the US Navy.</second>
<third points = '300' answer = 'Tim Berners-Lee'>Called the father of the world wide web, this man is the director of the W3C.</third>
<fourth points = '400' answer = 'Lawrence Lessig'>An American academic and political activist who founded the Creative Commons, this man lobbies for reduced legal restrictions on copyrights and trademarks in the technology sector.</fourth>
<fifth points = '500' answer = 'Ada Lovelace'>This woman, known as the world's first computer programmer was also a Countess.</fifth>
</category>
What I am having trouble with is that I am returning all of the text in between the tags for the entire category with the code I have written. I need to get the text for each tag, first, second, third, etc. as well as getting the point value and answer attribute values from inside the XML tags to use in my code. I am not sure what I need to do to get these values. Thank you ahead of time to anyone who would like to help me out.