473,320 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

reading the xml attribute in a asp.net page

Below is my asp.net code which should fetch the correct answer from the xml document.
how can i store the xml attribute (i.e to an object or string)?
it is throwing an error object reference not set to the instance of the object
could any one help me
<?xml version="1.0" encoding="utf-8" ?>
<quiz>
<mchoice>
<question>Which of the following characteristics distinguishes man from the other animals </question>
<answer>Ability to stand erect </answer>
<answer>Ability to adapt to the environment </answer>
<answer correct="yes">Ability to make tools</answer>
<answer>Ability to live in a group</answer>
</mchoice>
<mchoice>
<question>There is freedom of association between members of all strata including intermarriage
and equalitarian social relations in </question>
<answer correct="yes">open-class </answer>
<answer>open ethnic</answer>
<answer>closed caste</answer>
<answer>closed estate</answer>
</mchoice>
<mchoice>
<question>Who among the following emphasized the role of Charismatic Leadership in social change</question>
<answer>Sorokin</answer>
<answe>Pareto</answe>
<answer correct="yes">Max Weber </answer>
<answer>Rajani Kothari</answer>
</mchoice>
<mchoice>
<question>Opposition to which one of the following was the primary goal of the Kheda Movement of Gujarat </question>
<answer correct="yes">Taxes</answer>
<answer>Sudden price rise </answer>
<answer>Money lending class</answer>
<answer>Unpaid forced labour</answer>
</mchoice>
</quiz>

namespace quiz
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>

public class WebForm1 : System.Web.UI.Page
{

protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.RadioButtonList Rdlst;
protected System.Web.UI.WebControls.Button BtnSbt;
string StartTime;
XmlDocument xmldoc=new XmlDocument();
int totalquestion;
int questionno=1;
int score=0;
int[] answerarr=new int[10];

//XPathNodeIterator xpathnodeit=new XPathNodeIterator();

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Label1.Text="hello";

xmldoc.Load(Server.MapPath("quiz.xml"));
if (Page.IsPostBack!=true)
{
totalquestion=xmldoc.SelectNodes("/quiz/mchoice").Count;
Label1.Text=System.Convert.ToString(totalquestion) ;
ViewState["StartTime"]=DateTime.Now;
ShowQuestion(questionno);
ViewState["TotalQUestion"]=totalquestion;
}
}
public void ShowQuestion(int intquestionno)
{
XmlNodeList xmlnodelist;
Object xmlattr=new object();
string str=null;
int i;
string strpath;
TimeSpan timespent;
Rdlst.Items.Clear();
ViewState["StartTime"]=DateTime.Now;
strpath="/quiz/mchoice["+intquestionno.ToString()+"]";
Label1.Text=questionno.ToString() + "." + xmldoc.SelectSingleNode(strpath+"/question").InnerXml;
xmlnodelist=xmldoc.SelectNodes(strpath+"/answer");

for( i = 0;i<=xmlnodelist.Count-1;i++)
{

Rdlst.Items.Add(new ListItem(xmlnodelist.Item(i).InnerText));
}
ViewState["QuestionNo"]=intquestionno;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Rdlst.SelectedIndexChanged += new System.EventHandler(this.Rdlst_SelectedIndexChange d);
this.BtnSbt.Click += new System.EventHandler(this.BtnSbt_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void Rdlst_SelectedIndexChanged(object sender, System.EventArgs e)
{

}

private void BtnSbt_Click(object sender, System.EventArgs e)
{
questionno=(int)ViewState["QuestionNo"];
totalquestion=(int)ViewState["TotalQUestion"];
questionno+=1;

if(questionno>totalquestion)
{
Response.Redirect("result.aspx");
}
else
ShowQuestion(questionno);
}
}
}
Dec 27 '06 #1
0 2259

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Jeff Thies | last post by:
I'm (still) having trouble reading the contents of an IFRAME (IE5). I have this: var my_iframe = document.frames; What I would want to do at that point is get either the...
12
by: Anna | last post by:
Hi all, I posted the same question this afternoon but my message isn't showing up, so I thought I'd give it another try.... in case you should see it later I apologize for posting the same...
6
by: anon | last post by:
Post Forwarding question...... For this control below, <asp:Button runat="server" PostTargetUrl="page2.aspx" /> The Attribute: PostTargetUrl="page2.aspx" Is this PostTargetUrl Attribute...
1
by: Sunil Pathi | last post by:
Thanks in Advance I have a XML file which is read from a .aspx page. I need to read through all the elements, find the values of them and pass them on to the stored procedure which updates the...
3
by: Carl Lindmark | last post by:
*Cross-posting from microsoft.public.dotnet.languages.csharp, since I believe the question is better suited in this XML group* Hello all, I'm having some problems understanding all the ins and...
6
by: Hans Kamp | last post by:
My program fails reading XML attributes. A fragment of the code is: private void showXmlNodeAtTreeNode(XmlNodeList xnl, TreeNode tn) { int i; for (i = 0; i < xnl.Count; i++) { XmlNode xn =...
1
by: SteveB | last post by:
I'm porting an application from Apache Xerces to .Net and am having a couple of small problems with deserialization. The XML that I'm reading comes from a variety of sources, and there are two...
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
0
by: panos100m | last post by:
Hi i can read everything from my xml file except a part that i can always get teh first items of each category (it will make more sence in a sec) So here is my xml <?xml version="1.0"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.