c# - How to read from an XML and display in a textbox and label in a Winform -
i creating survey application , having trouble reading xml file wrote display splash text inside of splash form , questions in actual survey form.
i writing questions , answers in xml program can reused creating different xml , reading rather hard-coding questions , answers. here xml structure:
<questions> <splashtext> <text>splash text displaying information , purpose of survey goes here</text> </splashtext> <question> <type>comboboxcontrol</type> <text>blah blah blah?</text> <choices> <choice>answer 1</choice> <choice default="true">answer 2</choice> <choice>answer 3</choice> <choice>answer 4</choice> </choices> <required>true</required> </question> .. .. </questions>
how can program read xml , put splash text textbox on splash form?
admittedly, haven't tested healthy debugging point out parsing code flawed. think might fix it, should @ xdocument queries in immediate window while debugging see if you're getting expect.
var xdocument = xdocument.load(@"c:\users\..\survey.xml"); var questionlist = xdocument .element("questions") .elements("question") .select(elem => new questions { questiontype = elem.element("type").value, questiontext = elem.element("text").value, splashscreentext = elem.element("splashtext").value, choices = elem.element("choices").elements("choice").select(ch => new choice { answerchoice = ch.value }).toarray() }).tolist();
edit: of course, taking second look, notice winforms code never calling in xmlparser, , xmlparser isn't returning list of questions objects. you're going need before can display anything.
Comments
Post a Comment