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_ItemDataB ound(objec t sender, System.Web.UI.WebControls. RepeaterIt emEventArg s e)
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingIt em))
{
Repeater distractorRepeater = (Repeater) item.FindControl("choicesR epeater");
DataRowView drv = (DataRowView) item.DataItem;
distractorRepeater.DataSou rce = drv.CreateChildView("quest ion_distra ctor");
distractorRepeater.DataBin d();
//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</dis tractor1>
<distractor2>False</distra ctor2>
</question>
<question>
<stem>A Bird is a vehicle? </stem>
<distractor1>True</distrac tor1>
<distractor2 isCorrect="true">False</di stractor2>
</question>
<question>
<stem>A Jetta is an animal? </stem>
<distractor1>True</distrac tor1>
<distractor2 isCorrect="true">False</di stractor2>
</question>
</quiz>
Code behind partial sample:
private void questionRepeater_ItemDataB
{
RepeaterItem item = e.Item;
if( (item.ItemType == ListItemType.Item) || (item.ItemType == ListItemType.AlternatingIt
{
Repeater distractorRepeater = (Repeater) item.FindControl("choicesR
DataRowView drv = (DataRowView) item.DataItem;
distractorRepeater.DataSou
distractorRepeater.DataBin
//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</dis
<distractor2>False</distra
</question>
<question>
<stem>A Bird is a vehicle? </stem>
<distractor1>True</distrac
<distractor2 isCorrect="true">False</di
</question>
<question>
<stem>A Jetta is an animal? </stem>
<distractor1>True</distrac
<distractor2 isCorrect="true">False</di
</question>
</quiz>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER