无法显示我的XML中的所有元素 [英] Unable to display all the elements in my XML

查看:82
本文介绍了无法显示我的XML中的所有元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用XML显示一组问题和这些问题的4个答案.

我的XML文件中总共有15个问题.但是我只能显示前两个问题.我无法追踪.

下面是代码.

Hello All,

I am trying to display a set of questions and 4 answers to these questions using XML.

There are total of 15 questions in my XML File. But i am able to display only first 2 questions. I am unable to trace that.

Below is the code.

public partial class _Default : System.Web.UI.Page 
{
    int total = 15;
    int qno = 1;

    protected void Page_Load(object sender, EventArgs e)
    {
        LoadQuiz(qno);

    }
    public void LoadQuiz(int qno)
    {
        string questionPath = Server.MapPath("Business-Questions.xml");
        XPathDocument xdoc = new XPathDocument(questionPath);
        XPathNavigator xnav = xdoc.CreateNavigator();
        XPathNodeIterator iterator;

        string anspath;
        int looper;

        anspath="/quiz/mchoice["+qno.ToString()+"]";
        iterator = xnav.Select(anspath + "/question");
        iterator.MoveNext();
        Label1.Text = qno.ToString() + "." + iterator.Current.Value;
        
        iterator = xnav.Select(anspath = "/answer");
        RadioButtonList1.Items.Clear();
        looper = 0;

        while (iterator.MoveNext())
        {
            looper += 1;
            RadioButtonList1.Items.Add(new ListItem(iterator.Current.Value,looper.ToString()));
        }


    }











    protected void Button1_Click(object sender, EventArgs e)
    {
        if (qno != total)
        {
            qno++;
            LoadQuiz(qno);
        }
        else
        {
            Response.Write("BYEEE");
        }



    }
}




用作VB代码时,相同的代码可以正常工作,它与CP中给出的相同.在CP中,它用作ASP页中的脚本.

但是我不想用作脚本.我想在文件后面的代码中使用它.

我不明白这是什么错误....但是我无法跟踪它.

这是XML.




The same code when used as VB code is working fine, it is the same code given in CP. In CP, it is used as a script in the ASP Page.

But I don''t want to use as a script. I want to use it in the code behind file.

I am not understanding what is the error....But I am unable to trace it.

Here is the XML.

<?xml version="1.0" encoding="UTF-8"?>

<quiz xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Questions.xsd">
<mchoice>
<question>Which cricketer is the Brand Ambassador of Band Aid?</question>
<answer correct="yes">i) Virender Sehwag</answer>
<answer>iI) Sachin Tendulkar</answer>
<answer>iii) Saurav Ganguly</answer>
<answer>iv) Yuvraj Singh</answer>
</mchoice>
<mchoice>
<question>Paul Jacobs is the CEO of which of the below Companies?</question>
<answer>i) Sun Microsystems</answer>
<answer>ii) EDS</answer>
<answer correct="yes">iii) Qualcomm</answer>
<answer>iv) Microsoft</answer>
</mchoice>
<mchoice>
<question>Who coined the word "Transformational Leadership ?"</question>
<answer>i) Pradeep Sindhu</answer>
<answer>ii) Philip Kotlar </answer>
<answer>iii) Samuel A Dipiazza</answer>
<answer correct="yes">iv) James McGregor Burns</answer>
</mchoice>
<mchoice>
<question>Aditya Birla collaborated with which foreign company to roll out an
insurance scheme</question>
<answer>i) Vysya</answer>
<answer correct="yes">ii) SunLife</answer>
<answer>iii) Sanmar</answer>
<answer>iv) Max New York Life</answer>
</mchoice>
<mchoice>
<question>Citi Bank co brands for which Oil Company ?</question>
<answer correct="yes">i) HP</answer>
<answer>ii) IOCL</answer>
<answer>iii) BPCL</answer>
<answer>iv) IBP</answer>
</mchoice>
<mchoice>
<question>Who is the CEO of Uninor ?</question>
<answer correct="yes">i) Stein-Erik Vellan</answer>
<answer>ii) Arun Sarin</answer>
<answer>iii) Kumar Mangalam Birla</answer>
<answer>iv) Gary Scott Thompson</answer>
</mchoice>
<mchoice>
<question>In which year Vijaya Bank attain the status of the Nationalized Bank</question>
<answer>i) 1970</answer>
<answer>ii) 1982</answer>
<answer correct="yes">iii) 1980</answer>
<answer>iv) 1958</answer>
</mchoice>
<mchoice>
<question>Which company has the slogan - "India's Family Store" ?</question>
<answer correct="yes">i) Pantaloon</answer>
<answer>Provogue</answer>
<answer>Hrawats</answer>
<answer>Peter England</answer>
</mchoice>
<mchoice>
  <question>Who is the CEO of HP ?</question>
<answer correct="yes">i) Léo Apotheker</answer>
<answer>ii) Mark Hurd</answer>
<answer>iii) Tim Cook</answer>
<answer>iv) Tim Paine</answer>
</mchoice>
<mchoice>
<question>India has least or nominal trade relation swith wchich country ?</question>
<answer>i) Japan</answer>
<answer correct="yes">ii) Uganda</answer>
<answer>iii) Great Britain</answer>
<answer>iv) South Africa</answer>
</mchoice>
<mchoice>
<question>"Interest Rate Policy" is a component of </question>
<answer correct="yes">i) Monetary Policy</answer>
<answer>ii) Direct Policy</answer>
<answer>iii) Fiscal Policy</answer>
<answer>iv) Trade Policy</answer>
</mchoice>
<mchoice>
<question>After a great change in the price of a commodity, there is no change in its demand.
The demand is known as</question>
<answer>i) Very Elastic</answer>
<answer>ii) Elastic</answer>
<answer>iii) Inelastic</answer>
<answer correct="yes">iv) Inelastic</answer>
</mchoice>
<mchoice>
<question>What is the currency of Kenya called ?</question>
<answer>i) Kenyan Dollar</answer>
<answer correct="yes">ii) Kenyan Shilling</answer>
<answer>iii) Kenyan Real</answer>
<answer>iv) Kenyan Kina</answer>
</mchoice>
<mchoice>
<question>What is Costa Rica's main export?</question>
<answer>i) Coffee</answer>
<answer>ii) Bananas</answer>
<answer>iii) Pineapples</answer>
  <answer correct="yes">iv) i,ii,iii</answer>
</mchoice>
<mchoice>
<question>Which is the largest petroleum refinery and where it is located ?</question>
<answer>i) Ras Tanura Refinery, Eastern Province, Saudi Arabia</answer>
<answer correct="yes">ii) Reliance Jamnagar Complex(RIL), Jamnagar, India</answer>
<answer>iii) Paraguana Refining Complex (CRP), Amuay and Cardón, Venezuela</answer>
<answer>iv) Tehran Oil refinery, Tehran, Iran</answer>
</mchoice>
</quiz>





请协助...我已经搜索了许多站点,但仍然无法修复!!!!:confused :: confused :: confused:
在此先多谢!!!!





Kindly assist...I have already searched many sites, but still unable to fix !!!!:confused::confused::confused:
Many Thanks in Advance !!!

推荐答案

我认为XML解析器对引号并不满意.尝试将每个问题和答案放在CDATA块中.

I think the XML parser isn''t to happy about the quotes. Try to put each question and answer in CDATA block.

<![CDATA[
Who coined the word "Transformational Leadership ?"
]]>



祝你好运!


作为旁注:我不认为它是用问号创造的;)



Good luck!


As side note: I don''t think it''s was coined with a question mark ;)


这篇关于无法显示我的XML中的所有元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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