You can use XDocument
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
foreach(XElement questionElement in xDocument.Root.Elements("question"))
{
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* do something with them here */
}
}
Using the attribute id to bind all select boxes:
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
foreach(XElement questionElement in xDocument.Root.Elements("question"))
{
string id = questionElement.Attribute("id").Value;
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* bind selectbox options here, using id,text,value */
}
}
Using id to bind one select box:
string id = "title";
string xml = ""; /* your xml */
XDocument xDocument = XDocument.Parse(xml);
XElement questionElement = xDocument.Root.Elements("question").SingleOrDefault(e => e.Attribute("id").Value == "title");
if (questionElement != null)
{
foreach(XElement optionElement in questionElement.Elements("option"))
{
string text = optionElement.Element("text").Value;
string value = optionElement.Element("value").Value;
/* bind selectbox options here, using id,text,value */
}
}