[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2007-03-23
2
Medium Priority
?
327 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Accepted Solution

by:
Gautham Janardhan earned 2000 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

650 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