Tuesday, November 19, 2013

<?xml version="1.0" encoding="ISO-8859-1"?>
<Leagues>
  <League name="UKIRESA">
    <Race name="Newcastle">
<Time name="1">2:24</Time>
<Time name="2">2:42</Time>
    </Race>
   <Race name="Poole">
<Time name="1">3:08</Time>
<Time name="2">3:28</Time>
<Time name="6">4:58</Time>
    </Race>
  </League>
  <League name="USALARC">
    <Race name="Hipo Chile">
<Time name="1">5:30</Time>
    </Race>
    <Race name="Laurel Park">
<Time name="1">5:35</Time>
    </Race>
    <Race name="Gulfstream">
<Time name="1">6:55</Time>
<Time name="6">8:45</Time>
<Time name="7">9:15</Time>
    </Race>
  </League>
</Leagues>

Programming

Computer programming (often shortened to programming) is the comprehensive process that leads from an original formulation of a computing problem to executable programs. It involves activities such as analysis, understanding, and generically solving such problems resulting in an algorithm, verification of requirements of the algorithm including its correctness and its resource consumption, implementation (or coding) of the algorithm in a target programming language, testingdebugging, and maintaining the source code, implementation of the build system and management of derived artefacts such as machine code of computer programs. The algorithm is often only represented in human-parseable form and reasoned about using logic. Source code is written in one or more programming languages (such as C++C#JavaPythonSmalltalkJavaScript, etc.). The purpose of programming is to find a sequence of instructions that will automate performing a specific task or solve a given problem. The process of programming thus often requires expertise in many different subjects, including knowledge of the application domain, specialized algorithms and formal logic.
Within software engineering, programming (the implementation) is regarded as one phase in a software development process.
There is an on-going debate on the extent to which the writing of programs is an art form, a craft, or anengineering discipline.[1] In general, good programming is considered to be the measured application of all three, with the goal of producing an efficient and evolvable software solution (the criteria for "efficient" and "evolvable" vary considerably). The discipline differs from many other technical professions in that programmers, in general, do not need to be licensed or pass any standardized (or governmentally regulated) certification tests in order to call themselves "programmers" or even "software engineers." Because the discipline covers many areas, which may or may not include critical applications, it is debatable whether licensing is required for the profession as a whole. In most cases, the discipline is self-governed by the entities which require the programming, and sometimes very strict environments are defined (e.g. United States Air Force use of AdaCore and security clearance). However, representing oneself as a "Professional Software Engineer" without a license from an accredited institution is illegal in many parts of the world.
Another on-going debate is the extent to which the programming language used in writing computer programs affects the form that the final program takes. This debate is analogous to that surrounding the Sapir–Whorf hypothesis[2] in linguistics and cognitive science, which postulates that a particular spoken language's nature influences the habitual thought of its speakers. Different language patterns yield different patterns of thought. This idea challenges the possibility of representing the world perfectly with language, because it acknowledges that the mechanisms of any language condition the thoughts of its speaker community.


js - view

function ShowRacePerLeague(l) {
    event.preventDefault();
    var path = "/Exam/GetLeague/";
    $.ajax({
        url: path,
        dataType: "json",
        data: { league: l },
        type: 'POST',
        success: function (data) {
            $('#tblOutput').html(data);
        }
    });
}



@{
    ViewBag.Title = "ExamHome";
}
<script src="../../Scripts/main.js" type="text/javascript"></script>
<h2>
    ExamHome</h2>
<div style="margin-top: 200px">
    <input type="button" style="height: 30px; width: 100px; float: left; cursor: pointer;
        background-color: Red" value="UK/IRE/SA" onclick="ShowRacePerLeague('UKIRESA')">
     <input type="button" style="height: 30px; width: 100px; float: left; cursor: pointer;
        background-color: Red" value="USA/LARC" onclick="ShowRacePerLeague('USALARC')">
</div>
<div style="clear: both">
</div>
<div id="tblOutput">
    @ViewBag.Table
</div>

Co

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using Exam.Models;

namespace Exam.Controllers
{
    public class ExamController : Controller
    {
        //
        // GET: /Exam/
        private ExamModel eModel = new ExamModel(@"C:\Users\Leagues.xml");
        public ActionResult ExamHome()
        {
            string str = eModel.ReadXML("All");
            var table = MvcHtmlString.Create(str);
            ViewBag.Table = table;
            return View();
        }

        [HttpPost]
        public JsonResult GetLeague(string league)
        {
            return Json(eModel.ReadXML(league));
        }

    }
}

Model

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Xml;
using System.IO;

 public class ExamModel
    {
        readonly string xmlPath = string.Empty;

        public ExamModel(string path)
        {
            xmlPath = path;
        }

        public string ReadXML(string league)
        {
            string str = "<table>";
            XPathDocument doc = new XPathDocument(xmlPath);
            XPathNavigator nav = doc.CreateNavigator();
            XPathExpression exp = (league == "All") ? nav.Compile(@"/Leagues/League") : nav.Compile(@"/Leagues/League[@name='" + league + "']");
            XPathNodeIterator iterator = nav.Select(exp);

            while (iterator.MoveNext())
            {
                XPathNavigator selector = iterator.Current.SelectSingleNode("@name");
                string strLeague = selector == null ? string.Empty : selector.Value.ToString();

                XPathNodeIterator iterator1 = iterator.Current.Select("Race");
                while (iterator1.MoveNext())
                {
                    string strRaceName = string.Empty;
                    string strTime = string.Empty;
                    strRaceName += GetNode(iterator1.Current, "@name").Trim();
                    strTime += GetNode(iterator1.Current, "Time").Trim();
                    str += "<tr>" + strRaceName + strTime + "</tr>";
                }
            }
            return str;
        }

        private string GetNode(XPathNavigator path, string xPath)
        {
            string res = string.Empty;
            int i = 0;
            XPathNodeIterator iterator = path.Select(xPath);
            while (iterator.MoveNext())
            {
                i++;
                res += "<td>" + iterator.Current.Value.ToString() + "</td>";
            }
            return res;
        }
    }