Solved

How to grab an attribute from XML node with code behind code?

Posted on 2007-03-23
2
320 Views
Last Modified: 2013-11-26
I have an xml file I am using to build a true and false question with (see below). There is an attribute named isCorrect in the distractor node that I'd like to grab during the ItemDataBound process, what syntax would I use to access that attribute from the code behind?

Code behind partial sample:
            private void questionRepeater_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
            {
                  RepeaterItem item = e.Item;
                  if( (item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingItem))
                        {
                        Repeater distractorRepeater = (Repeater) item.FindControl("choicesRepeater");
                        DataRowView drv = (DataRowView) item.DataItem;
                        distractorRepeater.DataSource = drv.CreateChildView("question_distractor");
                        distractorRepeater.DataBind();
                        //Response.Write(" item: " +distractorRepeater.);
                        }// end of if itemtype...            
            }// end of questionRepeater...

XML:
<?xml version="1.0" encoding="utf-8" ?>
<quiz>
      <question>
            <stem>An Apple is a fruit?</stem>
            <distractor1 isCorrect="true">True</distractor1>
            <distractor2>False</distractor2>      
      </question>

      <question>
            <stem>A Bird is a vehicle? </stem>
            <distractor1>True</distractor1>
            <distractor2 isCorrect="true">False</distractor2>      
      </question>            
      <question>
            <stem>A Jetta is an animal? </stem>
            <distractor1>True</distractor1>
            <distractor2 isCorrect="true">False</distractor2>      
      </question>      
</quiz>
0
Comment
Question by:cbittner
2 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 500 total points
ID: 18785760
     System.Xml.XmlDocument FDoc =
                        new System.Xml.XmlDocument();
                  FDoc.Load(@"e:\temp\test.xml");
                  System.Xml.XmlNodeList FList =
                        FDoc.SelectNodes("/quiz/question/distractor1");
                  for(int i=0;i<FList.Count;i++)
                  {
                        Console.WriteLine(FList[i].Attributes["isCorrect"].Value);
                  }
0
 

Author Comment

by:cbittner
ID: 18792947
Thanks.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now