从XML向页面添加数据时出现问题 [英] Issue in adding data from XML into my page

查看:60
本文介绍了从XML向页面添加数据时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一个标签和一个单选按钮列表.

数据存储在XML文件中.

这是以下显示数据的代码.但是我看不到任何数据.

我在此行收到空引用异常"的运行时错误.

Dear All,

I am having a label and a Radio Button List.

The data is stored in XML file.

This is the following code to display the data. But I am unable to see any data.

I get a run time error for Null Reference Exception at this line.

Label1.Text = intQuestionNo.ToString() + "." + xdoc.SelectSingleNode(strXpath + "/question").InnerXml;



整个代码如下.





The entire code is as below.



public partial class _Default : System.Web.UI.Page
{
    //int intTotalQuestion;
    int intQuestionNo=1;
    XmlDocument xdoc = new XmlDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
        string XmlPath = Server.MapPath("Questions.xml");
        xdoc.Load(XmlPath);
        ShowQuestion(intQuestionNo);

    }

    {
        XmlNodeList xNodeList;
        //object xNodeAttr;
        string strXpath;
        int i;
        strXpath = "/questions/mchoice[" + intQuestionNo.ToString() + "]";
        Label1.Text = intQuestionNo.ToString() + "." + xdoc.SelectSingleNode(strXpath + "/question").InnerXml;
        xNodeList = xdoc.SelectNodes(strXpath + "/answer");
        RadioButtonList1.Items.Clear();
        for(i=0;i<xNodeList.Count-1;i++)
        {
           RadioButtonList1.Items.Add(new ListItem(xNodeList.Item(i).InnerText));
       }
        //RadioButtonList1.Items.Add(new ListItem(xNodeList.Item(0).InnerText));

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        intQuestionNo += 1;
        ShowQuestion(intQuestionNo);
    }





:confused:

请协助

Mukund K





:confused:

Kindly assist

Mukund K

推荐答案

首先选择documentElement.

Select the documentElement first.

Label1.Text = intQuestionNo.ToString() + "." + xdoc.documentElement.SelectSingleNode(strXpath + "/question").InnerXml;



祝你好运!



Good luck!


这篇关于从XML向页面添加数据时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆