My XML file looks like the one below, I'm trying to use Sharp C code so that it only populates a combo box with questions based on the name of the selected course name. So, for example, if they choose XML programming in the course combobox field, only questions for XML programming will be displayed in the combobox question. What will be my XPath to do this? Any help would be appreciated.
if (comboBoxCourse.SelectedItem.ToString() == selectNode.InnerText ) { try { XmlNodeList loadQuestions = loadDoc.SelectNodes("//Course/Questions"); foreach (XmlNode xml in loadQuestions) { if (comboBoxCourse.SelectedItem.ToString() == selectNode.InnerText) comboBoxQuestions.Items.Add(xml.InnerText); else continue; } } catch (XmlException ex) { MessageBox.Show(ex.ToString()); } }
<?xml version="1.0" encoding="utf-8" ?> <Courses> <Course> <Name>Direct X Programming</Name> <Professor>Michael Feeney</Professor> <Questions>Are you a Ninja</Questions> <Questions>What version of Direct X do we use?</Questions> </Course> <Course> <Name>XML Programming</Name> <Professor>Michael Feeney</Professor> <Questions>Are you an XML Ninja?</Questions> <Questions>What does XML stand for?</Questions> </Course> <Course> <Name>Windows GUI</Name> <Professor>Leanne Wong</Professor> <Questions>What is a treeview?</Questions> <Questions>What is a database?</Questions> </Course> </Courses>
Finch source share