I’m using C# (.Net framework 4 with VS 2010) for reading a dynamically generated XML file. The file is containing answers for questions (MCQ radio buttons, MCQ multi answer check boxes and simple text fields). Question IDs and option IDs are generated from database.
I just need to extract Question ID and relevent Answer ID(s). Sample XML is as follows.
<?xml version="1.0"?>
<Root>
<!-- Radio Button Answers -->
<Question_6_Option>26</Question_6_Option>
<Question_8_Option>32</Question_8_Option>
<Question_9_Option>off</Question_9_Option>
<!-- Check Box Answers -->
<Question_15_Option_41>41</Question_15_Option_41>
<Question_15_Option_42>off</Question_15_Option_42>
<Question_16_Option_43>43</Question_16_Option_43>
<!-- Text Box Answers -->
<Question_23_Text>London</Question_23_Text>
</Root>
Above XML is generated in the format,
Tag name format: Question_QuestionID_SomeLogic based on answer type (radio, multiple options or text box).
If a user unanswered for a question value will display as “off”. Those no need to consider.
How can I get the Question ID and Answer value from C#?
Thanks,
Chatur
NOT AN ANSWER, but included here rather than in the comments to make the XML more readable:
I’d suggest that if you’re able to make your XML more computer readable – i.e. remove data from the tag names and put it into attributes to make it simpler to parse.
As @NewAmbition stated above, the answer to your actual question is already elsewhere on this site.