I need to parse XML files that will be a certain format and then work out whether the home or away team has won and then allocate 3 or 1 points to a HTML table (Overall Points Column) determined by the result, I would prefer to use JQuery to do this.
results.xml Code:
<?xml version="1.0"?>
<title>Results</title>
<results>
<result id="1234">
<hometeam>
<name>Roma</name>
<score>2</score>
</hometeam>
<awayteam>
<name>Lazio</name>
<score>0</score>
</awayteam>
</result>
</results>
HTML Code:
<table id="table">
<th>Team</th>
<th>Played</th>
<th>Won</th>
<th>Drawn</th>
<th>Lost</th>
<th>Total Goals</th>
<th>Overall Points</th>
<tr>
<td>Roma</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Lazio</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Inter</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>Milan</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
</table>
JQuery Code:
function showData() {
$.ajax({
type: "GET",
url: "results.xml",
dataType: "xml",
This is all I have so far for the JQuery code.
Where would the calculation to work out the result go?
if (hometeam score > awayteam score)
{ add 3 to hometeams Overall Points}
else if (hometeam score = awayteam score)
{ add 1 to hometeams Overall Points and add 1 to awayteams Overall Points}
else
{ add 3 to awayteams Overall Points}
How would I evaluate the hometeam and awayteam score and update the correct team in the HTML table?
Thank you for your help.