Link to home
Start Free TrialLog in
Avatar of cbittner
cbittner

asked on

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

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>
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cbittner
cbittner

ASKER

Thanks.